Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't replace the file" error on first edit of file with elevation #803

Open
Px-x64 opened this issue Feb 19, 2024 · 1 comment
Open

"Can't replace the file" error on first edit of file with elevation #803

Px-x64 opened this issue Feb 19, 2024 · 1 comment
Labels

Comments

@Px-x64
Copy link

Px-x64 commented Feb 19, 2024

Far Manager version

3.0.6278

OS version

10.0.19045.4046

Other software

None

Steps to reproduce

  1. Start Far under regular user who can elevate to administrator.
  2. Open C:\Windows\System32\drivers\etc\hosts file for editing.
  3. Add "127.0.0.1 test.com" line to the end of the file.
  4. Save file.
  5. Receive Access Denied dialog, press OK
  6. Receive system UAC dialog, allow Far to make changes

Expected behavior

File is saved without any issues

Actual behavior

On first edit after boot/Far start/sometimes on consequent edits you got the following error:

╔═══════════════════════════════════════════ Editor ═══════════════════════════════════════════╗
║                                     Cannot save the file                                     ║
║                            C:\Windows\System32\drivers\etc\hosts                             ║
╟──────────────────────────────────────────────────────────────────────────────────────────────╢
║                                    Can't replace the file                                    ║
║ 0x00000020 - The process cannot access the file because it is being used by another process. ║
╟──────────────────────────────────────────────────────────────────────────────────────────────╢
║                                     { Retry } [ Cancel ]                                     ║
╚══════════════════════════════════════════════════════════════════════════════════════════════╝

F3

errno:
0x00000000 - No error
LastError:
0x00000020 - The process cannot access the file because it is being used by another process.
NTSTATUS:
0xC0000043 - A file cannot be opened because the share access flags are incompatible.

Upon pressing Retry the file is successfully saved, but you have a temporary file (like FAR1C12.tmp) present in the folder.

I've tried to capture a trace in Process Monitor, but it is a bit noisy, because upon Far actions other apps like Edge/Slack are starting to sniff hosts file. I see two "PRIVILEGE NOT HELD" results for Far CreateFile calls, and then two "SHARING VIOLATION", and finally "ACCESS DENIED".
It looks like some kind of race condition here, and it is not clear what triggers it from Far side, because before Far tries to write the file, other apps doesn't look into it.
Also, it would be nice to at least remove temporary file in case if retry on save was successful.

@Px-x64 Px-x64 added the bug label Feb 19, 2024
@chevcheli0s
Copy link

3.0.6300 the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants