Error: failed to rename file (Access is denied. (os error 5))
zohnannor opened this issue · comments
Describe the bug
To Reproduce
Steps to reproduce the behavior:
- Run
$env:RUST_BACKTRACE="full"; cargo spellcheck fix
- Complete the steps (go through all errors reported)
- It tries to save temp file and then replace the original with it
-
Error: 0: failed to rename file from E:\my_path\.spellcheck.tmpd1c18dca-90a0-4552-8397-6b052802e37a to \\?\E:\my_path\src\lib.rs 1: Access is denied. (os error 5) Location: /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\result.rs:1911 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1: onig_get_start_by_callout_args<unknown> at <unknown source file>:<unknown line> 2: onig_get_start_by_callout_args<unknown> at <unknown source file>:<unknown line> 3: onig_get_start_by_callout_args<unknown> at <unknown source file>:<unknown line> 4: onig_get_start_by_callout_args<unknown> at <unknown source file>:<unknown line> 5: store_pointer<unknown> at <unknown source file>:<unknown line> 6: store_pointer<unknown> at <unknown source file>:<unknown line> 7: store_pointer<unknown> at <unknown source file>:<unknown line> 8: store_pointer<unknown> at <unknown source file>:<unknown line> 9: store_pointer<unknown> at <unknown source file>:<unknown line> 10: store_pointer<unknown> at <unknown source file>:<unknown line> 11: store_pointer<unknown> at <unknown source file>:<unknown line> 12: store_pointer<unknown> at <unknown source file>:<unknown line> 13: store_pointer<unknown> at <unknown source file>:<unknown line> 14: store_pointer<unknown> at <unknown source file>:<unknown line> 15: onig_get_syntax_op2<unknown> at <unknown source file>:<unknown line> 16: store_pointer<unknown> at <unknown source file>:<unknown line> 17: onig_unicode_define_user_property<unknown> at <unknown source file>:<unknown line> 18: BaseThreadInitThunk<unknown> at <unknown source file>:<unknown line> 19: RtlUserThreadStart<unknown> at <unknown source file>:<unknown line> Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Expected behavior
The process ends without errors and replaces my old file with the new one.
Please complete the following information:
- System: Win10
- Obtained:
cargo install --locked cargo-spellcheck
- Version:
cargo-spellcheck 0.9.6
Additional context
My terminal is ran under Administrator privileges
Is your directory a special thing, i.e. a shared network folder or such? Can you replace the the file manually? I don't posses a windows machine to test this unfortunately, the CI passes when cross compiling and running wine as emulator.
os error 5
on windows means access denied, so that's a hint, but I am not sure how much I can help there.
Can you replace the the file manually?
Yep, I can delete my old file, rename .spellcheck.tmp<UUID> and place it where it needs to be.
Is your directory a special thing,
No, just a directory I created for my projects awhile ago. No shared network, nothing special.
Here is the steps to reproduce from creating the project to witnessing the error:
PS C:\User\Username\> E:
PS E:\> mkdir my_path
PS E:\> cd .\my_path\
PS E:\my_path> ca new spell
Created binary (application) `spell` package
PS E:\my_path> cd spell
PS E:\my_path> # I've edited my main.rs file
PS E:\my_path\spell> bat .\src\main.rs
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: .\src\main.rs
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ /// Spelilng erorr;
2 │ struct S;
3 │
4 │ fn main() {
5 │ println!("Hello, world!");
6 │ }
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
PS E:\my_path\spell> $env:RUST_BACKTRACE=1; ca spellcheck fix
error: spellcheck(Hunspell)
--> \\?\E:\my_path\spell\src\main.rs:1
|
1 | Spelilng erorr;
| ^^^^^^^^
(1/2) Apply this suggestion [y,n,q,a,d,j,e,?]?
Spelunking
» Spelling
`Spelilng`
error: spellcheck(Hunspell)
--> \\?\E:\my_path\spell\src\main.rs:1
|
1 | Spelilng erorr;
| ^^^^^
(2/2) Apply this suggestion [y,n,q,a,d,j,e,?]?
err
» error
`erorr`
Error:
0: failed to rename file from E:\my_path\spell\.spellcheck.tmpf29a673f-4c65-448a-ab33-2fe5bb5cda05 to \\?\E:\my_path\spell\src\main.rs
1: Access is denied. (os error 5)
Location:
/rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\result.rs:1911
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1: onig_get_start_by_callout_args<unknown>
at <unknown source file>:<unknown line>
2: onig_get_start_by_callout_args<unknown>
at <unknown source file>:<unknown line>
3: onig_get_start_by_callout_args<unknown>
at <unknown source file>:<unknown line>
4: onig_get_start_by_callout_args<unknown>
at <unknown source file>:<unknown line>
5: store_pointer<unknown>
at <unknown source file>:<unknown line>
6: store_pointer<unknown>
at <unknown source file>:<unknown line>
7: store_pointer<unknown>
at <unknown source file>:<unknown line>
8: store_pointer<unknown>
at <unknown source file>:<unknown line>
9: store_pointer<unknown>
at <unknown source file>:<unknown line>
10: store_pointer<unknown>
at <unknown source file>:<unknown line>
11: store_pointer<unknown>
at <unknown source file>:<unknown line>
12: store_pointer<unknown>
at <unknown source file>:<unknown line>
13: store_pointer<unknown>
at <unknown source file>:<unknown line>
14: store_pointer<unknown>
at <unknown source file>:<unknown line>
15: onig_get_syntax_op2<unknown>
at <unknown source file>:<unknown line>
16: store_pointer<unknown>
at <unknown source file>:<unknown line>
17: onig_unicode_define_user_property<unknown>
at <unknown source file>:<unknown line>
18: BaseThreadInitThunk<unknown>
at <unknown source file>:<unknown line>
19: RtlUserThreadStart<unknown>
at <unknown source file>:<unknown line>
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
PS E:\my_path\spell>
That is indeed strange, nothing seems to prevent cargo-spellcheck
from renaming the file. I'll try to elaborate on this issue more.
Hey, I did a little bit of research. The reason this error happens is: you can't rename file if it is not closed.
in this lines:
cargo-spellcheck/src/action/mod.rs
Lines 296 to 325 in 9736a6d
wr
is not closed, but it's renamed to another file.
Thank you, I'll fix this for the next release :)
I thought the fix would be simple: just drop writer
before renaming so it would close the file but no, the the error is still present.
May I open a PR when I'll resolve this? I've spent whole evening on this, debugging and reading sources and I really want to help fix it 😃 Moreover, this error happens on my machine (for some weird reason) so I can easily test the fix locally.
Ofc! Feel free to open a PR at any time! I am more than happy to aid where I can :)
Hint: it might be enough to explicitly drop the writer
and wr
in
cargo-spellcheck/src/action/mod.rs
Line 317 in 9736a6d