Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ build-backend = "setuptools.build_meta"

[project]
name = "pycpio"
version = "1.4.1"
version = "1.4.2"

authors = [
{ name="Desultory", email="[email protected]" },
]
Expand Down
13 changes: 6 additions & 7 deletions src/pycpio/cpio/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def from_dir(path: Path, parent=None, relative=False, *args, **kwargs):
return data

@staticmethod
def from_path(path: Path, relative=False, *args, **kwargs):
def from_path(path: Path, relative=False, resolve_symlink=False, *args, **kwargs):
"""
Create a CPIOData object from a path.
If a name is provided, it will be used instead of the resolved path.
Expand Down Expand Up @@ -101,15 +101,14 @@ def from_path(path: Path, relative=False, *args, **kwargs):
if not kwargs.pop("absolute", False):
kwargs["name"] = kwargs["name"].lstrip("/")

# Get the inode number from the path
kwargs["ino"] = path.stat().st_ino

# Get the mode type from the supplied path
kwargs["mode"] = mode_bytes_from_path(path)

# Use the path's uid and gid if not provided
kwargs["uid"] = kwargs.pop("uid", path.stat().st_uid)
kwargs["gid"] = kwargs.pop("gid", path.stat().st_gid)
for stat in ("ino", "uid", "gid"):
try: # Try to get the stat from the kwargs, otherwise, get it from the path
kwargs[stat] = kwargs.pop(stat, getattr(path.stat(), f"st_{stat}"))
except FileNotFoundError:
kwargs[stat] = 0 # If the symlink target doesn't exist, set the stat to 0

header = CPIOHeader(*args, **kwargs)
data = CPIOData.get_subtype(b"", header, *args, **kwargs)
Expand Down
5 changes: 4 additions & 1 deletion src/pycpio/cpio/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def __init__(self, *args, **kwargs):
if kwargs.get("recursive", False):
symlink_path = symlink_path.lstrip("/")
self.data = symlink_path.encode("ascii")
self.header.mtime = path.stat().st_mtime
try:
self.header.mtime = path.stat().st_mtime
except FileNotFoundError:
self.header.mtime = 0 # default to 0 if file not found
elif self.data is None:
raise ValueError("path must be specified for symlinks")

Expand Down
4 changes: 4 additions & 0 deletions tests/test_cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def test_newc_from_kwargs(self):
for attr, value in header_data.items():
self.assertEqual(getattr(test_header, attr), value)

def test_invalid_symlink_target(self):
test_symlink = Path(self.workdir.name) / 'test_symlink'
test_symlink.symlink_to('/a/totally/nonexistent/path')
self.cpio.append_recursive(self.workdir.name)

if __name__ == '__main__':
main()
Loading