Repository: ilai-deutel/kibi (language: rust)

Issue:
Unix: Return error when trying to open a device file
`kibi /dev/random` should fail with an error message

[std](https://doc.rust-lang.org/std/index.html)::[os](https://doc.rust-lang.org/std/os/index.html)::[unix](https://doc.rust-lang.org/std/os/unix/index.html)::[fs](https://doc.rust-lang.org/std/os/unix/fs/index.html)::[FileTypeExt](https://doc.rust-lang.org/std/os/unix/fs/trait.FileTypeExt.html#) can be used to determine the file type.


Discussion / hints:
Hello, I’m quite new to Rust but I wish to try with this issue 🙂
@ilmanzo Great, thank you! Let me know if you have any questions

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a449442a..5fb9f913 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -55,7 +55,9 @@ jobs:
       - uses: actions/checkout@v2
       - name: Install gcc-multilib
         if: matrix.target == 'i686-unknown-linux-gnu'
-        run: sudo apt-get install gcc-multilib
+        run: |
+          sudo apt-get update
+          sudo apt-get install gcc-multilib
       - name: Install Rust toolchain
         uses: actions-rs/toolchain@v1
         with:
diff --git a/src/editor.rs b/src/editor.rs
index b5a623a7..b2752571 100644
--- a/src/editor.rs
+++ b/src/editor.rs
@@ -1,6 +1,8 @@
 #![allow(clippy::wildcard_imports)]
 
-use std::io::{self, BufRead, BufReader, ErrorKind::NotFound, Read, Seek, Write};
+use std::io::{
+    self, BufRead, BufReader, ErrorKind::InvalidInput, ErrorKind::NotFound, Read, Seek, Write,
+};
 use std::iter::{self, repeat, successors};
 use std::{fmt::Display, fs::File, path::Path, process::Command, thread, time::Instant};
 
@@ -422,6 +424,11 @@ impl Editor {
     /// Try to load a file. If found, load the rows and update the render and syntax highlighting.
     /// If not found, do not return an error.
     fn load(&mut self, path: &Path) -> Result<(), Error> {
+        let ft = std::fs::metadata(path)?.file_type();
+        if !(ft.is_file() || ft.is_symlink()) {
+            return Err(io::Error::new(InvalidInput, "Invalid input file type").into());
+        }
+
         match File::open(path) {
             Ok(file) => {
                 for line in BufReader::new(file).split(b'\n') {


Test patch: