Commit cc1a16c
authored
fix: allow rename to overwrite read-only destination on Windows when deduplicating Dune cache (#13713)
In the Dune cache, when a temp artifact already exists in the cache,
Dune attempts deduplication by deleting the temp artifact, linking it to
the file already in the cache, and then moving the temp artifact to the
build directory.
The last step fails on Windows because Dune sets a read-only attribute
on the destination file, causing `Unix.rename` to fail with `EACCES` in
this case. Since the operation fails, Dune does not consider the file
cached. Combined with the fact that this seems to happen quite often [1]
on Windows, this effectively nullifies the cache speedup.
This PR creates a helper function that removes the read-only attribute
on the destination file before trying to overwrite it (similar to the
existing `win32_unlink`) and use it in the deduplication logic of the
cache, fixing the issue.
_Note: This issue does not exist on Unix. This discrepancy is also being
addressed directly on OCaml's side:
ocaml/ocaml#14602
The test dedup.t already exhibits the issue on Windows. The `dune_cmd
stat hardlinks _build/default/target` command returns 1 instead of the
expected 3. This PR bumps the result to 2. To make the test completely
pass, another issue around `Io.portable_hardlink` on Windows still needs
to be addressed [1].
[1] It seems that the fact that on windows dune always copies files
instead of trying to create a hardlink is linked to the fact that this
deduplication happen more often on windows. See #13714.
---------
Signed-off-by: Roven Lamar Gabriel <nevor@nevor.net>1 parent 2419738 commit cc1a16c
4 files changed
+22
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
207 | 224 | | |
208 | 225 | | |
209 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| |||
0 commit comments