-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Environment
Current develop branch HEAD
Description
LLFile::rename() fails under Windows when the new_name already exists while the Posix standard for rename() says that it should simply create the new file anyhow, such that at no point there does not exist any new_name for other processes.
This last one may be a bit hard to guarantee under Windows without a lot of testing and debugging and low level file tinkering, but making it not fail when the new_name already exists is fairly trivial by calling directly MoveFileExW() with the according flags rather than the cludgy Windows C runtime replacement _wrename(), which does actually nothing else than calling that function too, but without the according flag. This results in quite some places of the viewer source code in conditional code on LL_WINDOWS that removes the new_name before calling LLFile::rename(). That seems very unnecessary.
Similarly while Posix remove() is documented to work on both files and directories, LLFile::remove() on Windows will only work on files since the used _wremove() does simply call DeleteFileW(), which can't delete empty directories. While this seems to be not something that has been worked around in code to much, it still is an inconsistency.
There are two possible fixes to LLFile::remove():
1: adopt Posix behaviour and find out if the path is for a directory and then call _wrmdir() and otherwise call _wremove()
2: or make LLFile::remove() deviate from the Posix way and change the call in the non-Windows portion to unlink() to only work on files.
I personally tend to favor the first option, not at least because of the comment in the beginning of llfile.cpp about this trying to follow the Posix standard.
Reproduction steps
look at llfile.cpp source
This repo is using Opire - what does it mean? 👇
💵 Everyone can add rewards for this issue commenting
/reward 100
(replace 100
with the amount).🕵️♂️ If someone starts working on this issue to earn the rewards, they can comment
/try
to let everyone know!🙌 And when they open the PR, they can comment
/claim #4805
either in the PR description or in a PR's comment.🪙 Also, everyone can tip any user commenting
/tip 20 @fmartian
(replace 20
with the amount, and @fmartian
with the user to tip).📖 If you want to learn more, check out our documentation.