mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-16 15:16:44 +00:00
GODT-1865: fixed trailing temp file left when migrating cache.
This commit is contained in:
@ -229,17 +229,17 @@ func (u *Users) MigrateCache(srcPath, dstPath string) error {
|
|||||||
// (read-only is conserved). Do copy instead.
|
// (read-only is conserved). Do copy instead.
|
||||||
tmp, err := ioutil.TempFile(srcPath, "tmp")
|
tmp, err := ioutil.TempFile(srcPath, "tmp")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer func() {
|
// Removal of tmp file cannot be deferred, as we are going to try to move the containing folder.
|
||||||
tmp.Close() //nolint:errcheck,gosec
|
if err = tmp.Close(); err == nil {
|
||||||
os.Remove(tmp.Name()) //nolint:errcheck,gosec
|
if err = os.Remove(tmp.Name()); err == nil {
|
||||||
}()
|
if err = os.Rename(srcPath, dstPath); err == nil {
|
||||||
|
|
||||||
if err := os.Rename(srcPath, dstPath); err == nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logrus.WithError(err).Warn("Cannot write to source: do copy to new destination instead of rename")
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.WithError(err).Warn("Cannot write to source: do copy to new destination instead of rename")
|
||||||
|
|
||||||
// Rename failed let's try an actual copy/delete
|
// Rename failed let's try an actual copy/delete
|
||||||
if err = copyFolder(srcPath, dstPath); err != nil {
|
if err = copyFolder(srcPath, dstPath); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user