Skip to content

Conversation

@spdjudd
Copy link
Contributor

@spdjudd spdjudd commented Oct 19, 2022

Fixes issue #277

Change Summary

  1. Do nothing if renaming a file to have the same path as it currently has - previously the file was unlinked then an exception raised when trying to copy
  2. Raise an explicit exception when attempting to rename a directory - the implementation only supports rename/replace of files, which raises an exception from within _move_file() if passed a directory

Tests

I've added test conditions where it seemed appropriate within the existing test methods to exercise these changes - happy to move to separate test methods if preferred?

Do nothing if renaming to the same path
Explicit exception when attempting to rename a dir
if self.is_dir():
raise CloudPathIsADirectoryError(
f"Path {self} is a directory; rename/replace the files recursively."
)
Copy link
Member

Choose a reason for hiding this comment

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

Does pathlib error if you call replace on a directory? I assume not. If not, can we add an issue to track implementing replace for directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - I just checked and pathlib replace and rename both work for directories - I'll go ahead and add the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I just checked and I think this is already logged as issue #64

@pjbull
Copy link
Member

pjbull commented Oct 20, 2022

Thanks @spdjudd. If all the tests except the live server ones pass, I'll move these over to a local fork to make sure everything works there and then merge. Would you mind filing the issue I mentioned above?

@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2022

Codecov Report

Merging #278 (5ca7b71) into master (b7f6010) will decrease coverage by 0.3%.
The diff coverage is 100.0%.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #278     +/-   ##
========================================
- Coverage    94.8%   94.4%   -0.4%     
========================================
  Files          20      20             
  Lines        1314    1318      +4     
========================================
- Hits         1246    1245      -1     
- Misses         68      73      +5     
Impacted Files Coverage Δ
cloudpathlib/cloudpath.py 93.6% <100.0%> (+<0.1%) ⬆️
cloudpathlib/s3/s3client.py 92.9% <0.0%> (-2.7%) ⬇️
cloudpathlib/gs/gsclient.py 92.8% <0.0%> (-1.8%) ⬇️

@pjbull pjbull changed the base branch from master to 278-live-tests October 20, 2022 15:54
@pjbull pjbull merged commit 72daa1f into drivendataorg:278-live-tests Oct 20, 2022
pjbull added a commit that referenced this pull request Oct 20, 2022
* Prevent file loss/exceptions when renaming: (#278)

Do nothing if renaming to the same path
Explicit exception when attempting to rename a dir

* Update HISTORY.md

Co-authored-by: Simon Judd <[email protected]>
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