From 4688838eb6aade966012c7385832dc458f3b2a0f Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Mon, 22 Jun 2020 16:13:46 +0200 Subject: [PATCH 1/3] Ignore special files (BLK, CHR, FIFO, SOCKET) Fixes #3124, fixes #3546 TODO: we should add some tests but I'm unsure about portability here. Signed-off-by: Emilio Jesus Gallego Arias --- CHANGES.md | 3 +++ src/dune_engine/file_tree.ml | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 53af2078284..bd14a23f176 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,9 @@ - Cram tests: when checking that all test directories contain a `run.t` file, skip empty directories. These can be left around by git. (#3753, @emillon) +- Ignore special files (BLK, CHR, FIFO, SOCKET) , fixes #3124, #3546 + (#3570, @ejgallego) + 2.7.0 (13/08/2020) ------------------ diff --git a/src/dune_engine/file_tree.ml b/src/dune_engine/file_tree.ml index 98566bc0e1c..81c191193d1 100644 --- a/src/dune_engine/file_tree.ml +++ b/src/dune_engine/file_tree.ml @@ -139,6 +139,17 @@ end = struct || String.is_suffix fn ~suffix:".swp" || String.is_suffix fn ~suffix:"~" + (* Returns [true] for special files such as character devices of sockets; see + #3124 for more on issues caused by special devices *) + let is_special (st_kind : Unix.file_kind) = + match st_kind with + | S_CHR + | S_BLK + | S_FIFO + | S_SOCK -> + true + | _ -> false + let of_source_path path = match Path.readdir_unsorted (Path.source path) with | Error unix_error -> @@ -162,15 +173,16 @@ end = struct if Path.Source.is_in_build_dir path then Skip else + let fstat = Path.stat (Path.source path) in let is_directory, file = - match Path.stat (Path.source path) with + match fstat with | exception _ -> (false, File.dummy) | { st_kind = S_DIR; _ } as st -> (true, File.of_stats st) | _ -> (false, File.dummy) in if is_directory then Right (fn, path, file) - else if is_temp_file fn then + else if is_temp_file fn || is_special fstat.st_kind then Skip else Left fn) From 90ec63a6a6a23cade01130d06a0edac99adecd98 Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Wed, 2 Sep 2020 18:42:33 +0200 Subject: [PATCH 2/3] Test to check that we ignore special files. Signed-off-by: Emilio Jesus Gallego Arias --- test/blackbox-tests/test-cases/special_files.t/bar.ml | 1 + test/blackbox-tests/test-cases/special_files.t/dune | 3 +++ test/blackbox-tests/test-cases/special_files.t/dune-project | 1 + test/blackbox-tests/test-cases/special_files.t/run.t | 5 +++++ test/blackbox-tests/test-cases/special_files.t/src/dune | 2 ++ test/blackbox-tests/test-cases/special_files.t/src/p.ml | 1 + 6 files changed, 13 insertions(+) create mode 100644 test/blackbox-tests/test-cases/special_files.t/bar.ml create mode 100644 test/blackbox-tests/test-cases/special_files.t/dune create mode 100644 test/blackbox-tests/test-cases/special_files.t/dune-project create mode 100644 test/blackbox-tests/test-cases/special_files.t/run.t create mode 100644 test/blackbox-tests/test-cases/special_files.t/src/dune create mode 100644 test/blackbox-tests/test-cases/special_files.t/src/p.ml diff --git a/test/blackbox-tests/test-cases/special_files.t/bar.ml b/test/blackbox-tests/test-cases/special_files.t/bar.ml new file mode 100644 index 00000000000..3b5e23e5623 --- /dev/null +++ b/test/blackbox-tests/test-cases/special_files.t/bar.ml @@ -0,0 +1 @@ +let _ = L.P.do_print () diff --git a/test/blackbox-tests/test-cases/special_files.t/dune b/test/blackbox-tests/test-cases/special_files.t/dune new file mode 100644 index 00000000000..58d8f3974b0 --- /dev/null +++ b/test/blackbox-tests/test-cases/special_files.t/dune @@ -0,0 +1,3 @@ +(executable + (name bar) + (libraries l)) diff --git a/test/blackbox-tests/test-cases/special_files.t/dune-project b/test/blackbox-tests/test-cases/special_files.t/dune-project new file mode 100644 index 00000000000..45acd3f0884 --- /dev/null +++ b/test/blackbox-tests/test-cases/special_files.t/dune-project @@ -0,0 +1 @@ +(lang dune 2.7) diff --git a/test/blackbox-tests/test-cases/special_files.t/run.t b/test/blackbox-tests/test-cases/special_files.t/run.t new file mode 100644 index 00000000000..2c1fb569a49 --- /dev/null +++ b/test/blackbox-tests/test-cases/special_files.t/run.t @@ -0,0 +1,5 @@ + $ mkfifo src/foo + $ dune build @all + $ _build/default/bar.exe + hi! + $ rm -f src/foo diff --git a/test/blackbox-tests/test-cases/special_files.t/src/dune b/test/blackbox-tests/test-cases/special_files.t/src/dune new file mode 100644 index 00000000000..644516e369b --- /dev/null +++ b/test/blackbox-tests/test-cases/special_files.t/src/dune @@ -0,0 +1,2 @@ +(library + (name l)) diff --git a/test/blackbox-tests/test-cases/special_files.t/src/p.ml b/test/blackbox-tests/test-cases/special_files.t/src/p.ml new file mode 100644 index 00000000000..f9f9e86f397 --- /dev/null +++ b/test/blackbox-tests/test-cases/special_files.t/src/p.ml @@ -0,0 +1 @@ +let do_print () = Format.printf "hi!@\n%!" From 242f58db312927a86fc5b45045dba78e535b9d35 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 2 Sep 2020 22:05:50 -0700 Subject: [PATCH 3/3] update CHANGES Signed-off-by: Rudi Grinberg --- CHANGES.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bd14a23f176..0b9c023aaf3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +Unreleased +---------- + +- Ignore special files (BLK, CHR, FIFO, SOCKET) , fixes #3124, #3546 + (#3570, @ejgallego) + 2.7.1 (2/09/2020) ----------------- @@ -20,9 +26,6 @@ - Cram tests: when checking that all test directories contain a `run.t` file, skip empty directories. These can be left around by git. (#3753, @emillon) -- Ignore special files (BLK, CHR, FIFO, SOCKET) , fixes #3124, #3546 - (#3570, @ejgallego) - 2.7.0 (13/08/2020) ------------------