Skip to content

Commit

Permalink
Make TarfileItem.name be of type PurePosixPath
Browse files Browse the repository at this point in the history
Rational from #409:

```py
>>> PureWindowsPath(*PurePosixPath('d/a\\b\\c.txt').parts)
PureWindowsPath('d/a/b/c.txt')
```

This means that we must relay the POSIX nature of the archive member
path to the users, because there is no way to express this as a platform
(windows) path -- and also no way to extract this file under an
equivalent name on an FS that uses windows-semantics. So a type
mismatch can be used to trigger mitigation strategies.

If feel like a clean(er) solution would be to change `TarFileItem` to
declare to have a `name` of type `PurePosixPath`.
  • Loading branch information
mih committed Jun 16, 2023
1 parent 59a6317 commit ced2561
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions datalad_next/iter_collections/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

@dataclass # sadly PY3.10+ only (kw_only=True)
class TarfileItem(FileSystemItem):
pass
name: PurePosixPath
"""TAR uses POSIX paths as item identifiers. Not all POSIX paths can
be represented on all (non-POSIX) file systems, therefore the item
name is represented in POSIX form, instead of a platform-dependent
``PurePath``."""


def iter_tar(
Expand Down Expand Up @@ -63,7 +67,7 @@ def iter_tar(
else FileSystemItemType.hardlink if member.islnk() \
else FileSystemItemType.specialfile
item = TarfileItem(
name=PurePath(PurePosixPath(member.name)),
name=PurePosixPath(member.name),
type=mtype,
size=member.size,
mode=member.mode,
Expand Down

0 comments on commit ced2561

Please sign in to comment.