Skip to content

Commit

Permalink
use protocol to decide if joinpath needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncopd committed Jun 17, 2024
1 parent 35b2c75 commit a69a5a7
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,15 +1010,25 @@ def rename(
maxdepth: int | None = None,
**kwargs: Any,
) -> UPath: # fixme: non-standard
target_ = UPath(target)
if target_.protocol and target_.protocol != self.protocol:
raise ValueError(
f"expected protocol {self.protocol!r}, got: {target_.protocol!r}"
)
target_ = target_.resolve()
parent = self.parent.resolve()
if not target_.is_relative_to(str(parent)):
target_ = parent.joinpath(target_)
target_protocol = get_upath_protocol(target)
if target_protocol:
if target_protocol != self.protocol:
raise ValueError(
f"expected protocol {self.protocol!r}, got: {target_protocol!r}"
)
if not isinstance(target, UPath):
target_ = UPath(target, **self.storage_options)
else:
target_ = target
# avoid calling .resolve for subclasses of UPath
if ".." in target_.parts or "." in target_.parts:
target_ = target_.resolve()
else:
parent = self.parent
# avoid calling .resolve for subclasses of UPath
if ".." in parent.parts or "." in parent.parts:
parent = parent.resolve()
target_ = parent.joinpath(os.path.normpath(target))
self.fs.mv(
self.path,
target_.path,
Expand Down

0 comments on commit a69a5a7

Please sign in to comment.