Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

fileutil.Replace - remove destination only when a directory. #636

Merged
merged 4 commits into from
Jun 24, 2019

Conversation

krasi-georgiev
Copy link
Contributor

In cases where a rename fails the fileutil.Replace would delete the
source files/folder.

There is no easy way to make directory renaming atomic, but for files
os.Rename is atomic and replaced the destination file so there is no
need to remove the destination file explicitly.

this was caught while working on the FS errors injections on rename in #583 with block.Delete . Before this change a failure during a rename would cause deleting the source meta and tombstone files.

In cases where a rename fails the fileutil.Replace would delete the
source files/folder.

There is no easy way to make directory renaming atomic, but for files
os.Rename is atomic and replaced the destination file so there is no
need to remove the destination file explicitly.

Signed-off-by: Krasi Georgiev <[email protected]>
Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine, wonder how it behaves on different OS systems than Linux though.

fileutil/fileutil.go Outdated Show resolved Hide resolved
@krasi-georgiev
Copy link
Contributor Author

I think it's fine, wonder how it behaves on different OS systems than Linux though.

yes probably broken for windows, but will wait for some Windows user to contribute the windows changes.

Signed-off-by: Krasi Georgiev <[email protected]>
Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes probably broken for windows, but will wait for some Windows user to contribute the windows changes

Not sure if that's right approach, we could ask someone to test it / add windows machines at some point to CI. However since os.Rename has this specified in method comment, I think it is likely it works (: so LGTM

// If newpath already exists and is not a directory, Rename replaces it.

@bwplotka bwplotka merged commit b5f9f9f into prometheus-junkyard:master Jun 24, 2019
@krasi-georgiev krasi-georgiev deleted the rename-bug branch June 24, 2019 12:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants