pathrs 0.2.4__tar.gz → 0.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pathrs-0.2.4 → pathrs-0.2.5}/PKG-INFO +1 -1
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/_internal.py +12 -1
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/_libpathrs_cffi/lib.pyi +20 -3
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/_pathrs.py +50 -11
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs.egg-info/PKG-INFO +1 -1
- {pathrs-0.2.4 → pathrs-0.2.5}/pyproject.toml +1 -1
- {pathrs-0.2.4 → pathrs-0.2.5}/setup.py +1 -1
- {pathrs-0.2.4 → pathrs-0.2.5}/COPYING +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/README.md +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/__init__.py +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/_libpathrs_cffi/__init__.pyi +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/pathrs_build.py +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/procfs.py +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs/py.typed +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs.egg-info/SOURCES.txt +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs.egg-info/dependency_links.txt +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs.egg-info/requires.txt +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/pathrs.egg-info/top_level.txt +0 -0
- {pathrs-0.2.4 → pathrs-0.2.5}/setup.cfg +0 -0
|
@@ -93,7 +93,7 @@ class PathrsError(Exception):
|
|
|
93
93
|
return None
|
|
94
94
|
|
|
95
95
|
err = libpathrs_so.pathrs_errorinfo(err_id)
|
|
96
|
-
if err == ffi.NULL: # type: ignore # TODO: Make this check nicer...
|
|
96
|
+
if err == ffi.NULL: # type: ignore[comparison-overlap,unused-ignore] # TODO: Make this check nicer...
|
|
97
97
|
return None
|
|
98
98
|
|
|
99
99
|
description = _pystr(err.description)
|
|
@@ -344,3 +344,14 @@ def _convert_mode(mode: str) -> int:
|
|
|
344
344
|
|
|
345
345
|
# We don't care about "b" or "t" since that's just a Python thing.
|
|
346
346
|
return flags
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
class SingletonClass(type):
|
|
350
|
+
"""Metaclass used to create singleton classes."""
|
|
351
|
+
|
|
352
|
+
_instances: dict[type, Type[Any]] = {}
|
|
353
|
+
|
|
354
|
+
def __call__(cls, *args, **kwargs): # type: ignore[no-untyped-def] # TODO: Not clear what annotations to use, and mypy appears to be confused by metaclasses.
|
|
355
|
+
if cls not in cls._instances:
|
|
356
|
+
cls._instances[cls] = super(SingletonClass, cls).__call__(*args, **kwargs)
|
|
357
|
+
return cls._instances[cls]
|
|
@@ -32,6 +32,13 @@ __PATHRS_MAX_ERR_VALUE: ErrorId
|
|
|
32
32
|
def pathrs_errorinfo(err_id: Union[ErrorId, int]) -> CError: ...
|
|
33
33
|
def pathrs_errorinfo_free(err: CError) -> None: ...
|
|
34
34
|
|
|
35
|
+
# pathrs_version_info_t *
|
|
36
|
+
@type_check_only
|
|
37
|
+
class VersionInfo:
|
|
38
|
+
version_string: CString
|
|
39
|
+
|
|
40
|
+
def pathrs_version(info: VersionInfo, size: int) -> Union[ErrorId, int]: ...
|
|
41
|
+
|
|
35
42
|
# uint64_t
|
|
36
43
|
ProcfsOpenFlags: TypeAlias = int
|
|
37
44
|
PATHRS_PROCFS_NEW_UNMASKED: ProcfsOpenFlags
|
|
@@ -83,7 +90,11 @@ def pathrs_inroot_creat(
|
|
|
83
90
|
rootfd: RawFd, path: CString, flags: int, filemode: int
|
|
84
91
|
) -> Union[RawFd, ErrorId]: ...
|
|
85
92
|
def pathrs_inroot_rename(
|
|
86
|
-
|
|
93
|
+
old_rootfd: RawFd,
|
|
94
|
+
old_path: CString,
|
|
95
|
+
new_rootfd: RawFd,
|
|
96
|
+
new_path: CString,
|
|
97
|
+
flags: int,
|
|
87
98
|
) -> Union[Literal[0], ErrorId]: ...
|
|
88
99
|
def pathrs_inroot_rmdir(rootfd: RawFd, path: CString) -> Union[Literal[0], ErrorId]: ...
|
|
89
100
|
def pathrs_inroot_unlink(
|
|
@@ -100,10 +111,16 @@ def pathrs_inroot_mknod(
|
|
|
100
111
|
rootfd: RawFd, path: CString, mode: int, dev: int
|
|
101
112
|
) -> Union[Literal[0], ErrorId]: ...
|
|
102
113
|
def pathrs_inroot_hardlink(
|
|
103
|
-
|
|
114
|
+
old_rootfd: RawFd,
|
|
115
|
+
old_path: CString,
|
|
116
|
+
new_rootfd: RawFd,
|
|
117
|
+
new_path: CString,
|
|
118
|
+
flags: int,
|
|
104
119
|
) -> Union[Literal[0], ErrorId]: ...
|
|
105
120
|
def pathrs_inroot_symlink(
|
|
106
|
-
|
|
121
|
+
target: CString,
|
|
122
|
+
rootfd: RawFd,
|
|
123
|
+
linkpath: CString,
|
|
107
124
|
) -> Union[Literal[0], ErrorId]: ...
|
|
108
125
|
def pathrs_inroot_readlink(
|
|
109
126
|
rootfd: RawFd, path: CString, linkbuf: CBuffer, linkbuf_size: int
|
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
import os
|
|
13
13
|
|
|
14
14
|
import typing
|
|
15
|
-
from typing import Any, IO, Union
|
|
15
|
+
from typing import Any, IO, Union, cast
|
|
16
|
+
import warnings
|
|
16
17
|
|
|
17
18
|
# TODO: Remove this once we only support Python >= 3.11.
|
|
18
19
|
from typing_extensions import TypeAlias
|
|
19
20
|
|
|
20
21
|
from ._internal import (
|
|
22
|
+
# Generic helpers.
|
|
23
|
+
SingletonClass,
|
|
21
24
|
# File type helpers.
|
|
22
25
|
FileLike,
|
|
23
26
|
WrappedFd,
|
|
@@ -28,6 +31,7 @@ from ._internal import (
|
|
|
28
31
|
INTERNAL_ERROR,
|
|
29
32
|
# CFFI helpers.
|
|
30
33
|
_cstr,
|
|
34
|
+
_pystr,
|
|
31
35
|
_cbuffer,
|
|
32
36
|
)
|
|
33
37
|
from ._libpathrs_cffi import lib as libpathrs_so
|
|
@@ -51,11 +55,46 @@ __all__ = [
|
|
|
51
55
|
# Core api.
|
|
52
56
|
"Root",
|
|
53
57
|
"Handle",
|
|
58
|
+
"library_version",
|
|
54
59
|
# Error api (re-export).
|
|
55
60
|
"PathrsError",
|
|
56
61
|
]
|
|
57
62
|
|
|
58
63
|
|
|
64
|
+
class VersionInfo(metaclass=SingletonClass):
|
|
65
|
+
"""Stores information about the runtime version of libpathrs.so."""
|
|
66
|
+
|
|
67
|
+
_VERSION_INFO_TYPE = "pathrs_version_info_t *"
|
|
68
|
+
|
|
69
|
+
version_string: str
|
|
70
|
+
|
|
71
|
+
def __init__(self): # type: ignore[no-untyped-def] # TODO: mypy appears to struggle with metaclasses.
|
|
72
|
+
info = cast("libpathrs_so.VersionInfo", ffi.new(self._VERSION_INFO_TYPE))
|
|
73
|
+
info_size = ffi.sizeof(cast("Any", info))
|
|
74
|
+
|
|
75
|
+
size = libpathrs_so.pathrs_version(info, info_size)
|
|
76
|
+
if _is_pathrs_err(size):
|
|
77
|
+
raise PathrsError._fetch(size) or INTERNAL_ERROR
|
|
78
|
+
if size > 0:
|
|
79
|
+
# TODO: We should also output a warning if the size of
|
|
80
|
+
# pathrs_version_info_t is bigger than the number of fields in the
|
|
81
|
+
# python-native VersionInfo. Otherwise a rebuild will mask that
|
|
82
|
+
# Python callers cannot see any new fields.
|
|
83
|
+
warnings.warn(
|
|
84
|
+
f"pathrs_version returned extra data we could not parse (need {size} bytes but buffer was only {info_size})"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
self.version_string = _pystr(info.version_string)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def library_version() -> VersionInfo:
|
|
91
|
+
"""
|
|
92
|
+
Returns information about the runtime version of libpathrs.so.
|
|
93
|
+
This is just shorthand for VersionInfo().
|
|
94
|
+
"""
|
|
95
|
+
return VersionInfo() # type: ignore[no-untyped-call] # TODO: mypy appears to struggle with metaclasses.
|
|
96
|
+
|
|
97
|
+
|
|
59
98
|
class Handle(WrappedFd):
|
|
60
99
|
"A handle to a filesystem object, usually resolved using Root.resolve()."
|
|
61
100
|
|
|
@@ -266,7 +305,7 @@ class Root(WrappedFd):
|
|
|
266
305
|
"""
|
|
267
306
|
# TODO: Should we have a separate Root.swap() operation?
|
|
268
307
|
err = libpathrs_so.pathrs_inroot_rename(
|
|
269
|
-
self.fileno(), _cstr(src), _cstr(dst), flags
|
|
308
|
+
self.fileno(), _cstr(src), self.fileno(), _cstr(dst), flags
|
|
270
309
|
)
|
|
271
310
|
if _is_pathrs_err(err):
|
|
272
311
|
raise PathrsError._fetch(err) or INTERNAL_ERROR
|
|
@@ -359,35 +398,35 @@ class Root(WrappedFd):
|
|
|
359
398
|
if _is_pathrs_err(err):
|
|
360
399
|
raise PathrsError._fetch(err) or INTERNAL_ERROR
|
|
361
400
|
|
|
362
|
-
def hardlink(self,
|
|
401
|
+
def hardlink(self, target: str, linkname: str, /) -> None:
|
|
363
402
|
"""
|
|
364
403
|
Create a hardlink between two paths inside the Root.
|
|
365
404
|
|
|
366
|
-
|
|
367
|
-
*existing* file.
|
|
405
|
+
linkname is the path to the *new* hardlink, and target is a path to
|
|
406
|
+
the *existing* file.
|
|
368
407
|
|
|
369
408
|
A pathrs.Error is raised if the path for the new hardlink already
|
|
370
409
|
exists.
|
|
371
410
|
"""
|
|
372
411
|
err = libpathrs_so.pathrs_inroot_hardlink(
|
|
373
|
-
self.fileno(), _cstr(
|
|
412
|
+
self.fileno(), _cstr(target), self.fileno(), _cstr(linkname), 0
|
|
374
413
|
)
|
|
375
414
|
if _is_pathrs_err(err):
|
|
376
415
|
raise PathrsError._fetch(err) or INTERNAL_ERROR
|
|
377
416
|
|
|
378
|
-
def symlink(self,
|
|
417
|
+
def symlink(self, target: str, linkname: str, /) -> None:
|
|
379
418
|
"""
|
|
380
419
|
Create a symlink at the given path in the Root.
|
|
381
420
|
|
|
382
|
-
|
|
383
|
-
will point to. Note that
|
|
384
|
-
so there are no restrictions on what target you put.
|
|
421
|
+
linkname is the path to the *new* symlink, and target is what the
|
|
422
|
+
symlink will point to. Note that symlink contents are not verified on
|
|
423
|
+
Linux, so there are no restrictions on what target you put.
|
|
385
424
|
|
|
386
425
|
A pathrs.Error is raised if the path for the new symlink already
|
|
387
426
|
exists.
|
|
388
427
|
"""
|
|
389
428
|
err = libpathrs_so.pathrs_inroot_symlink(
|
|
390
|
-
|
|
429
|
+
_cstr(target), self.fileno(), _cstr(linkname)
|
|
391
430
|
)
|
|
392
431
|
if _is_pathrs_err(err):
|
|
393
432
|
raise PathrsError._fetch(err) or INTERNAL_ERROR
|
|
@@ -21,7 +21,7 @@ build-backend = "setuptools.build_meta"
|
|
|
21
21
|
[project]
|
|
22
22
|
name = "pathrs"
|
|
23
23
|
# TODO: Figure out a way to keep this version up-to-date with Cargo.toml.
|
|
24
|
-
version = "0.2.
|
|
24
|
+
version = "0.2.5"
|
|
25
25
|
description = "Python bindings for libpathrs, a safe path resolution library for Linux."
|
|
26
26
|
readme = "README.md"
|
|
27
27
|
keywords = ["libpathrs", "pathrs"]
|
|
@@ -22,7 +22,7 @@ def parse_pyproject() -> Dict[str, Any]:
|
|
|
22
22
|
openmode = "rb"
|
|
23
23
|
except ImportError:
|
|
24
24
|
# TODO: Remove this once we only support Python >= 3.11.
|
|
25
|
-
import toml as tomllib # type: ignore
|
|
25
|
+
import toml as tomllib # type: ignore # The types are not compatible.
|
|
26
26
|
|
|
27
27
|
openmode = "r"
|
|
28
28
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|