Closed idosavion closed 1 month ago
@tidwall, first of all, thanks for maintaining this project! Another approach would be to first try to perform the renaming and only delete the file and retry on failure. I think this one is more straight forward, but let me know if you prefer the one suggested here.
Can we do an optimistic check first and test for windows?
Such as :
var err error
if err = os.Rename(src, dest); err != nil {
if os == WINDOWS {
if err = os.Remove(dest); err == nil {
err = os.Rename(src, dest);
}
}
}
return err;
This way we will effectively keep the same syscall operations on posix systems, and it won't break the atomicity guarantees with moving and unlinking files that are opened by multiple processes.
Thanks for the quick response @tidwall! I confirmed the (modified) fix on windows
Thanks!
During Shrink, we try to move the temporary file which was created to the database's original location, this may fail on windows because if you try to rename a file to a name that already exists, the operation will fail with an "Access is denied" error (while succeed and overwrite the file on mac and linux).
Additionally, fixed a small typo in test