Skip to content

Commit

Permalink
cache.move fix target changed parent detection
Browse files Browse the repository at this point in the history
if the path being moved was already in the common parent with the
target then we would mistakenly error, the correct version is to
detect whether the target parent and source parent are the same
  • Loading branch information
tgbugs committed Nov 25, 2019
1 parent 264684e commit a62c3a6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions augpathlib/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,22 +680,23 @@ def move(self, *, remote=None, target=None, meta=None):
return target

common = self.commonpath(target).absolute()
target_parent = target.parent.absolute()
parent = self.parent.absolute()

assert target.name != self.name or common != parent
assert target.name != self.name or target_parent != parent

if common != parent:
if target_parent != parent:
_id = remote.id if remote else meta.id
log.warning('A parent of current file has changed location!\n'
f'{common}\n{self.relative_to(common)}\n'
f'{target.relative_to(common)}\n{_id}')


if not target.parent.exists():
if not target_parent.exists():
if remote is None: # we have to have a remote to pull parent structure
remote = self._remote_class(meta)

target.parent.mkdir_cache(remote)
target_parent.mkdir_cache(remote)

do_cast = not isinstance(target, self.__class__)
if do_cast:
Expand Down

0 comments on commit a62c3a6

Please sign in to comment.