Skip to content
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

Consider replacing shutil.copyfile() with os.rename() #3

Open
rukkal opened this issue Mar 18, 2020 · 1 comment
Open

Consider replacing shutil.copyfile() with os.rename() #3

rukkal opened this issue Mar 18, 2020 · 1 comment

Comments

@rukkal
Copy link

rukkal commented Mar 18, 2020

If subuid_tfile and subuid_file/subgid_file are on the same filesystem, you could use os.rename() instead of shutil.copyfile().

os.rename() will perform the rename(2) syscall under the hood, hence the operation will be atomic and subuid_file/subgid_file will always be in a valid state.

Alternatively you could use shutil.move(), but I think that os.rename() is safer because os.rename() fails if src and dst are not on the same device. IMO the failure is good because it means that either we get atomicity or a failure.

I would use os.rename() here

shutil.copyfile(subuid_tfile.name, cfg['subuid_file'])

and here

shutil.copyfile(subuid_tfile.name, cfg['subgid_file'])

what do you think?

@santisis
Copy link

santisis commented Jan 9, 2024

Have you notice that the source file on both 126 and 127 lines is the same? Renaming one file as two files just doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants