Skip to content

remove dir before copytree, use copy2 to keep metadata #545

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

Merged
merged 3 commits into from
Sep 27, 2017

Conversation

jasper1918
Copy link
Contributor

Relates to #544

This PR adds:

  • remove an existing directory before copying to avoid errors
  • replace copy with copy2 for files when copying in order to preserve metadata. copytree uses copy2. This way all metadata is consistent for files and dirs.

@cwl-bot
Copy link

cwl-bot commented Sep 26, 2017

Can one of the admins verify this patch?

@tetron
Copy link
Member

tetron commented Sep 26, 2017

Thanks @jasper1918 !

@tetron
Copy link
Member

tetron commented Sep 26, 2017

Jenkins, test this please

@@ -279,9 +279,11 @@ def moveIt(src, dst):
if src != dst:
_logger.debug("Copying %s to %s", src, dst)
if os.path.isdir(src):
if os.path.exists(dst):
shutil.rmtree(dst)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a check if dst is a directory. If it isn't a directory, it should use os.unlink() instead. (If you try to use shutil.rmtree on a regular file it will raise an exception).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @tetron. The isdir function is prob more appropriate in this case anyway. Not sure I understand the scenario where a src dir could equate to a dst file. The copy2 func will allow overwrites so no need to unlink in the else block.

Copy link
Member

Choose a reason for hiding this comment

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

If src is a directory but dst is a file, copytree() will fail. I believe the problem you're trying to solve is correctly overwriting files in the final directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair. Committed for completeness. ;)

@tetron
Copy link
Member

tetron commented Sep 27, 2017

Jenkins, test this please

@tetron tetron merged commit 8ea90c0 into common-workflow-language:master Sep 27, 2017
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

Successfully merging this pull request may close these issues.

3 participants