Skip to content

Commit b3b1b7f

Browse files
committed
fix(subst): ignore large files
Fixes #9538 This logs a warning for large files (>16MB on 32-bit systems). Signed-off-by: Etienne Millon <[email protected]>
1 parent c54da76 commit b3b1b7f

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

bin/subst.ml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,27 @@ let subst_string s path ~map =
120120
;;
121121

122122
let subst_file path ~map =
123-
let s = Io.read_file path in
124-
let s =
125-
if Path.is_root (Path.parent_exn path) && Package.is_opam_file path
126-
then "version: \"%%" ^ "VERSION_NUM" ^ "%%\"\n" ^ s
127-
else s
128-
in
129-
match subst_string s ~map path with
130-
| None -> ()
131-
| Some s -> Io.write_file path s
123+
match Io.with_file_in path ~f:Io.read_all_unless_large with
124+
| Error () ->
125+
let hints =
126+
if Sys.word_size = 32
127+
then
128+
[ Pp.textf
129+
"Dune has been built as a 32-bit binary so the maximum size \"dune subst\" \
130+
can operate on is 16MiB."
131+
]
132+
else []
133+
in
134+
User_warning.emit ~hints [ Pp.textf "Ignoring large file: %s" (Path.to_string path) ]
135+
| Ok s ->
136+
let s =
137+
if Path.is_root (Path.parent_exn path) && Package.is_opam_file path
138+
then "version: \"%%" ^ "VERSION_NUM" ^ "%%\"\n" ^ s
139+
else s
140+
in
141+
(match subst_string s ~map path with
142+
| None -> ()
143+
| Some s -> Io.write_file path s)
132144
;;
133145

134146
(* Extending the Dune_project APIs, but adding capability to modify *)

doc/changes/9811.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- subst: do not fail on 32-bit systems when large files are encountered. Just log a warning in this case. (#9811, fixes #9538, @emillon)

test/blackbox-tests/test-cases/subst/32bit.t

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ This test uses subst, which needs a git repository:
2626
create mode 100644 dune-project
2727
create mode 100644 large.dat
2828

29-
$ dune subst 2>&1 | head -n 6
30-
Error: exception Invalid_argument("Bytes.create")
31-
Raised by primitive operation at Stdune__Io.Make.eagerly_input_string in file
32-
"otherlibs/stdune/src/io.ml", line 273, characters 14-30
33-
Called from Stdune__Io.Make.read_all.(fun) in file
34-
"otherlibs/stdune/src/io.ml", line 308, characters 16-40
35-
Called from Stdune__Exn.protectx in file "otherlibs/stdune/src/exn.ml", line
29+
$ dune subst
30+
Warning: Ignoring large file: large.dat
31+
Hint: Dune has been built as a 32-bit binary so the maximum size "dune subst"
32+
can operate on is 16MiB.

0 commit comments

Comments
 (0)