Commit 93d5bfa
fix(ext/fs): retry without FILE_FLAG_BACKUP_SEMANTICS on Windows when driver rejects it (#34686)
## Summary
Some Windows file system drivers — notably ImDisk-backed memory disks —
reject `FILE_FLAG_BACKUP_SEMANTICS` for regular files and return
`ERROR_INVALID_FUNCTION` (\`os error 1\`).
Deno passes that flag so `CreateFile` can open directories with the same
code path as files, which causes \`Deno.readTextFile\`,
\`Deno.writeTextFile\`,
\`Deno.stat\`, \`Deno.lstat\` (and anything that goes through them, such
as
\`std/fs/exists\`) to fail on those volumes:
\`\`\`txt
Error: Incorrect function. (os error 1): readfile 'y:\a.txt'
Error: Incorrect function. (os error 1): writefile 'y:\test.txt'
Error: Incorrect function. (os error 1): stat 'y:\a.txt'
\`\`\`
This PR transparently retries the open without the flag when we see
`ERROR_INVALID_FUNCTION`. Directories will still fail to open on the
problematic drivers (they need the backup-semantics flag), but on those
drivers only regular-file operations actually need to succeed. Any
other error from the original open still propagates unchanged.
The fallback covers both code paths that explicitly set the flag on
Windows:
- `open_with_checked_path` (used by `read_file_*`, `write_file_*`,
`open_*`, and the text-file variants that delegate to them).
- `stat` / `lstat` (each open the path with `access_mode(0)` plus the
flag to grab metadata via `GetFileInformationByHandle` /
`NtQueryInformationFile`).
## Test plan
- [x] `cargo +1.95.0 check -p deno_fs` (Linux host)
- [x] `cargo +1.95.0 clippy -p deno_fs --no-deps`
- [x] `cargo +1.95.0 fmt --check -p deno_fs`
- [ ] CI Windows job exercises the standard read/write/stat code paths
Hard to add an automated test for the ImDisk-only failure mode here
since we'd need to provision a memory-disk volume on the Windows CI
runner.
Fixes #26257
Closes denoland/divybot#406
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>1 parent 68236a1 commit 93d5bfa
1 file changed
Lines changed: 94 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
903 | 903 | | |
904 | 904 | | |
905 | 905 | | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
| 906 | + | |
914 | 907 | | |
915 | 908 | | |
916 | 909 | | |
| |||
925 | 918 | | |
926 | 919 | | |
927 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
928 | 938 | | |
929 | 939 | | |
930 | 940 | | |
931 | 941 | | |
932 | 942 | | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
933 | 949 | | |
934 | 950 | | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
941 | 962 | | |
942 | 963 | | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
943 | 967 | | |
944 | 968 | | |
945 | 969 | | |
| |||
1221 | 1245 | | |
1222 | 1246 | | |
1223 | 1247 | | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
1227 | | - | |
1228 | | - | |
1229 | | - | |
1230 | | - | |
1231 | | - | |
1232 | | - | |
1233 | | - | |
1234 | | - | |
1235 | | - | |
1236 | | - | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
1245 | 1252 | | |
1246 | 1253 | | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
1254 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
1255 | 1286 | | |
1256 | | - | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
1257 | 1308 | | |
1258 | 1309 | | |
1259 | 1310 | | |
| |||
0 commit comments