-
Notifications
You must be signed in to change notification settings - Fork 811
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
fileblob: os.Rename does not work between different mount points #3294
Comments
Hmm, sorry about that. I'm not sure it's possible to fix both this bug and the one that led to that PR (leaked temp files). One option is to use I guess I could try a |
I considered using a "test" Probably the best plan is to add an |
Thanks for your quick reaction. Unfortunately, my project only uses go-cloud indirectly via another package so I cannot set the provided option. I think
|
Thanks, will add that to the docstring for fileblob. |
@vangent I'm wondering if you could do this approach by replacing the 2 fileblob calls to func CopyAndDelete(src, dst string) error {
// Open source file for reading
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()
// Get the source file's permissions
srcInfo, err := srcFile.Stat()
if err != nil {
return err
}
// Create destination file
dstFile, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_EXCL, srcInfo.Mode())
if err != nil {
return err
}
defer dstFile.Close()
// Copy the source file's content to the destination file
_, err = io.Copy(dstFile, srcFile)
if err != nil {
return err
}
// Delete the source file
err = os.Remove(src)
if err != nil {
return err
}
return nil
} |
I considered that, but it can result in partial writes and leaks (e.g., if the application exits during the copy, or after the copy but before the Remove); that's why we use I think what's there now is reasonable; it work fine in most situations, and if you are working on a mount you can either tell it that via |
Got it, yeah the leak for unexpected exit during copy would be an issue. Thanks for your responsiveness. For anyone else who will need to use the filepath.WalkDir(uri, func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() && strings.HasSuffix(d.Name(), ".tmp") {
err = os.Remove(path)
}
return err
}) |
@vangent minor-inconvenience: if there is no fixed release schedule, could you consider bumping the package version to v0.34.0 in order to use the |
Done |
…spects export-path config instead) google/go-cloud#3294
…spects config instead) google/go-cloud#3294
…spects 'export-path' config instead) google/go-cloud#3294
…spects 'export-path' config instead) google/go-cloud#3294
…spects 'export-path' config instead) google/go-cloud#3294
…spects 'export-path' config instead) google/go-cloud#3294
Describe the bug
Since 2693ff1 fileblob creates temporary files in
os.TempDir
. If the mount point of this directory is different from the directory the application is running in, the call to os.Rename (https://github.com/google/go-cloud/blob/37e3cd7ce28e7b8ff717c6e8352854b13921b496/blob/fileblob/fileblob.go#L775C2-L775C2) fails with the errorinvalid cross-device link
To Reproduce
then run
Expected behavior
No error.
Version
go version go1.20.7 linux/amd64
gocloud.dev v0.33.0
The text was updated successfully, but these errors were encountered: