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

Use shutil.move instead of os.rename #15

Open
tewarid opened this issue May 3, 2021 · 2 comments
Open

Use shutil.move instead of os.rename #15

tewarid opened this issue May 3, 2021 · 2 comments

Comments

@tewarid
Copy link

tewarid commented May 3, 2021

os.rename is unable to handle rename across file systems, or renames across read-only Docker overlayfs layers. The following statement may fail with error EXDEV (18).

os.rename(output_final_dir, output_old_dir)

shutil.move is able to handle renames across file systems and Docker overlayfs layers.

@james-antill
Copy link
Contributor

Did this come up in some automated/CI testing analysis?

The line, and function, you are referring to renames the name of a directory within another directory. For overlayfs you almost certainly want to shutil.rmtree the old directory instead of shutil.move'ing it. Probably need to add an option for that though, or do the rmtree aftger catching the exception.

@tewarid
Copy link
Author

tewarid commented May 4, 2021

Did this come up in some automated/CI testing analysis?

I came across this while analyzing a similar issue in createrepo_c that is used by Yocto Project/OpenEmbedded.

The line, and function, you are referring to renames the name of a directory within another directory. For overlayfs you almost certainly want to shutil.rmtree the old directory instead of shutil.move'ing it. Probably need to add an option for that though, or do the rmtree aftger catching the exception.

I've found that shutil.move does a recursive copy and then removes the source directory, but shutil.rmtree may be worth providing as an alternative for performance reasons.

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