flat-packager 0.5.1__tar.gz → 0.5.2__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.
- {flat_packager-0.5.1/src/flat_packager.egg-info → flat_packager-0.5.2}/PKG-INFO +7 -1
- {flat_packager-0.5.1 → flat_packager-0.5.2}/README.md +6 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/pyproject.toml +1 -1
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/__init__.py +1 -1
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/unpack.py +44 -3
- {flat_packager-0.5.1 → flat_packager-0.5.2/src/flat_packager.egg-info}/PKG-INFO +7 -1
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager.egg-info/SOURCES.txt +2 -1
- {flat_packager-0.5.1 → flat_packager-0.5.2}/tests/test_pack.py +3 -1
- {flat_packager-0.5.1 → flat_packager-0.5.2}/tests/test_roundtrip.py +1 -0
- flat_packager-0.5.2/tests/test_windows_paths.py +191 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/LICENSE +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/setup.cfg +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/archive.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/content.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/inspect.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/markdown.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/pack.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/patterns.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/secret_files.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/text_encoding.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager/verify.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager.egg-info/dependency_links.txt +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager.egg-info/entry_points.txt +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager.egg-info/requires.txt +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/src/flat_packager.egg-info/top_level.txt +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/tests/test_markdown.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/tests/test_restore_fuzz.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/tests/test_text_encoding.py +0 -0
- {flat_packager-0.5.1 → flat_packager-0.5.2}/tests/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flat-packager
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: Pack a repository into one flat text archive and restore it later.
|
|
5
5
|
Author: Thomas
|
|
6
6
|
License-Expression: MIT
|
|
@@ -355,6 +355,12 @@ As a second layer, restores create directories one component at a time without
|
|
|
355
355
|
following symlinks and create files exclusively (`O_EXCL`/`O_NOFOLLOW`). Writes
|
|
356
356
|
therefore cannot be routed outside the output directory, including through
|
|
357
357
|
names that collide on case-insensitive filesystems such as default macOS.
|
|
358
|
+
Every path component is joined only if it stays inside its parent directory.
|
|
359
|
+
|
|
360
|
+
On Windows, restores also reject names Windows cannot store safely: names
|
|
361
|
+
containing `:` (drive-relative paths such as `D:x`, or alternate data
|
|
362
|
+
streams), other characters Windows forbids, reserved device names such as
|
|
363
|
+
`NUL` or `aux.py`, and names ending in a dot or space.
|
|
358
364
|
|
|
359
365
|
[docs/FORMAT.md](docs/FORMAT.md#7-validation-performed-on-restore) lists
|
|
360
366
|
every validation rule.
|
|
@@ -320,6 +320,12 @@ As a second layer, restores create directories one component at a time without
|
|
|
320
320
|
following symlinks and create files exclusively (`O_EXCL`/`O_NOFOLLOW`). Writes
|
|
321
321
|
therefore cannot be routed outside the output directory, including through
|
|
322
322
|
names that collide on case-insensitive filesystems such as default macOS.
|
|
323
|
+
Every path component is joined only if it stays inside its parent directory.
|
|
324
|
+
|
|
325
|
+
On Windows, restores also reject names Windows cannot store safely: names
|
|
326
|
+
containing `:` (drive-relative paths such as `D:x`, or alternate data
|
|
327
|
+
streams), other characters Windows forbids, reserved device names such as
|
|
328
|
+
`NUL` or `aux.py`, and names ending in a dot or space.
|
|
323
329
|
|
|
324
330
|
[docs/FORMAT.md](docs/FORMAT.md#7-validation-performed-on-restore) lists
|
|
325
331
|
every validation rule.
|
|
@@ -22,6 +22,12 @@ ArchiveRecord = tuple[int, dict[str, Any]]
|
|
|
22
22
|
|
|
23
23
|
O_NOFOLLOW = getattr(os, "O_NOFOLLOW", 0)
|
|
24
24
|
O_BINARY = getattr(os, "O_BINARY", 0)
|
|
25
|
+
IS_WINDOWS = os.name == "nt"
|
|
26
|
+
WINDOWS_FORBIDDEN_CHARS = frozenset('<>:"|?*')
|
|
27
|
+
WINDOWS_RESERVED_NAMES = frozenset(
|
|
28
|
+
{"CON", "PRN", "AUX", "NUL", "CONIN$", "CONOUT$"}
|
|
29
|
+
| {f"{prefix}{suffix}" for prefix in ("COM", "LPT") for suffix in "123456789\u00b9\u00b2\u00b3"}
|
|
30
|
+
)
|
|
25
31
|
PERMISSION_BITS = 0o777
|
|
26
32
|
ALL_MODE_BITS = 0o7777
|
|
27
33
|
|
|
@@ -109,9 +115,44 @@ def safe_relative_parts(rel_path: str) -> tuple[str, ...]:
|
|
|
109
115
|
parts = tuple(rel_path.split("/"))
|
|
110
116
|
if any(part in ("", ".", "..") for part in parts):
|
|
111
117
|
raise ValueError(f"unsafe archive path: {rel_path}")
|
|
118
|
+
if IS_WINDOWS:
|
|
119
|
+
for part in parts:
|
|
120
|
+
reason = windows_unsafe_reason(part)
|
|
121
|
+
if reason is not None:
|
|
122
|
+
raise ValueError(f"unsafe archive path on Windows ({reason}): {rel_path}")
|
|
112
123
|
return parts
|
|
113
124
|
|
|
114
125
|
|
|
126
|
+
def windows_unsafe_reason(part: str) -> str | None:
|
|
127
|
+
"""Why ``part`` cannot be restored safely on Windows, or None if it can.
|
|
128
|
+
|
|
129
|
+
``:`` makes a drive-relative path (``D:x``) or an NTFS alternate data
|
|
130
|
+
stream (``file:stream``); device names such as ``NUL`` or ``aux.py``
|
|
131
|
+
address devices instead of files; trailing dots and spaces are silently
|
|
132
|
+
stripped, so ``name.`` would become ``name``.
|
|
133
|
+
"""
|
|
134
|
+
bad = sorted({char for char in part if char in WINDOWS_FORBIDDEN_CHARS or ord(char) < 32})
|
|
135
|
+
if bad:
|
|
136
|
+
return "forbidden character " + ", ".join(repr(char) for char in bad)
|
|
137
|
+
if part.endswith((".", " ")):
|
|
138
|
+
return "trailing dot or space"
|
|
139
|
+
if part.split(".", 1)[0].rstrip(" ").upper() in WINDOWS_RESERVED_NAMES:
|
|
140
|
+
return "reserved device name"
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def join_component(parent: Path, part: str) -> Path:
|
|
145
|
+
"""Join one validated component, refusing joins that leave ``parent``.
|
|
146
|
+
|
|
147
|
+
Platform-independent second layer: on Windows a component such as ``D:x``
|
|
148
|
+
would replace ``parent`` with a drive-relative path instead of extending it.
|
|
149
|
+
"""
|
|
150
|
+
joined = parent / part
|
|
151
|
+
if joined.parent != parent or joined.name != part:
|
|
152
|
+
raise ValueError(f"{part!r}: path component does not stay inside {parent}")
|
|
153
|
+
return joined
|
|
154
|
+
|
|
155
|
+
|
|
115
156
|
def ensure_safe_dir(root: Path, parts: tuple[str, ...]) -> Path:
|
|
116
157
|
"""Create ``root/parts`` one component at a time without following symlinks.
|
|
117
158
|
|
|
@@ -121,7 +162,7 @@ def ensure_safe_dir(root: Path, parts: tuple[str, ...]) -> Path:
|
|
|
121
162
|
"""
|
|
122
163
|
current = root
|
|
123
164
|
for index, part in enumerate(parts):
|
|
124
|
-
current = current
|
|
165
|
+
current = join_component(current, part)
|
|
125
166
|
try:
|
|
126
167
|
metadata = os.lstat(current)
|
|
127
168
|
except FileNotFoundError:
|
|
@@ -139,7 +180,7 @@ def create_new_file(root: Path, rel_path: str) -> tuple[Any, Path]:
|
|
|
139
180
|
"""Create a new file inside ``root``; never follow or replace existing entries."""
|
|
140
181
|
parts = safe_relative_parts(rel_path)
|
|
141
182
|
parent = ensure_safe_dir(root, parts[:-1])
|
|
142
|
-
target = parent
|
|
183
|
+
target = join_component(parent, parts[-1])
|
|
143
184
|
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | O_NOFOLLOW | O_BINARY
|
|
144
185
|
try:
|
|
145
186
|
fd = os.open(target, flags, 0o666)
|
|
@@ -365,7 +406,7 @@ def process_symlink_record(
|
|
|
365
406
|
write_new_file(write_root, path, (target + "\n").encode("utf-8"), None)
|
|
366
407
|
return
|
|
367
408
|
parts = safe_relative_parts(path)
|
|
368
|
-
output_target = ensure_safe_dir(write_root, parts[:-1])
|
|
409
|
+
output_target = join_component(ensure_safe_dir(write_root, parts[:-1]), parts[-1])
|
|
369
410
|
try:
|
|
370
411
|
os.symlink(target, output_target)
|
|
371
412
|
except FileExistsError as exc:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flat-packager
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: Pack a repository into one flat text archive and restore it later.
|
|
5
5
|
Author: Thomas
|
|
6
6
|
License-Expression: MIT
|
|
@@ -355,6 +355,12 @@ As a second layer, restores create directories one component at a time without
|
|
|
355
355
|
following symlinks and create files exclusively (`O_EXCL`/`O_NOFOLLOW`). Writes
|
|
356
356
|
therefore cannot be routed outside the output directory, including through
|
|
357
357
|
names that collide on case-insensitive filesystems such as default macOS.
|
|
358
|
+
Every path component is joined only if it stays inside its parent directory.
|
|
359
|
+
|
|
360
|
+
On Windows, restores also reject names Windows cannot store safely: names
|
|
361
|
+
containing `:` (drive-relative paths such as `D:x`, or alternate data
|
|
362
|
+
streams), other characters Windows forbids, reserved device names such as
|
|
363
|
+
`NUL` or `aux.py`, and names ending in a dot or space.
|
|
358
364
|
|
|
359
365
|
[docs/FORMAT.md](docs/FORMAT.md#7-validation-performed-on-restore) lists
|
|
360
366
|
every validation rule.
|
|
@@ -775,7 +775,8 @@ class IncludeAndSubdirTests(PackTestCase):
|
|
|
775
775
|
{p for p, t in paths.items() if t == "dir"}, {"src", "src/pkg", "src/pkg/deep"}
|
|
776
776
|
)
|
|
777
777
|
records = {r["path"]: r for _l, r in read_json_lines(self.archive) if "path" in r}
|
|
778
|
-
|
|
778
|
+
if os.name != "nt": # Windows has no POSIX directory permissions
|
|
779
|
+
self.assertEqual(records["src/pkg"]["mode"], 0o750)
|
|
779
780
|
restored = self.restore()
|
|
780
781
|
self.assertEqual((restored / "src" / "pkg" / "deep" / "c.py").read_text(), "c\n")
|
|
781
782
|
|
|
@@ -890,6 +891,7 @@ class IncludeAndSubdirTests(PackTestCase):
|
|
|
890
891
|
files, {"src/a.py", "src/pkg/b.py", "src/pkg/deep/c.py", "src/pkg/data.json"}
|
|
891
892
|
)
|
|
892
893
|
|
|
894
|
+
@unittest.skipIf(os.name == "nt", "Windows strips trailing spaces from names")
|
|
893
895
|
def test_subdir_keeps_significant_whitespace(self) -> None:
|
|
894
896
|
(self.source / "data").mkdir()
|
|
895
897
|
(self.source / "data" / "plain.txt").write_text("plain\n")
|
|
@@ -398,6 +398,7 @@ class RoundTripTests(unittest.TestCase):
|
|
|
398
398
|
self.assertEqual((output / "link" / "owned.txt").read_bytes(), b"owned\n")
|
|
399
399
|
self.assertEqual(list(outside.iterdir()), [])
|
|
400
400
|
|
|
401
|
+
@unittest.skipIf(os.name == "nt", "Windows has no POSIX permission bits")
|
|
401
402
|
def test_special_mode_bits_are_stripped_by_default(self) -> None:
|
|
402
403
|
archive = self.work_dir / "archive.flat.txt"
|
|
403
404
|
output = self.work_dir / "output"
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Windows-specific restore safety tests.
|
|
2
|
+
|
|
3
|
+
Windows path rules differ from POSIX: a component such as ``D:x`` is a
|
|
4
|
+
drive-relative path that replaces everything joined before it, ``name:stream``
|
|
5
|
+
addresses an NTFS alternate data stream, device names such as ``CON`` and
|
|
6
|
+
``NUL`` are reserved, and trailing dots and spaces are stripped. These tests
|
|
7
|
+
check that a restore never writes outside the output directory and rejects
|
|
8
|
+
such names. They only run on Windows.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import base64
|
|
14
|
+
import hashlib
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
import unittest
|
|
20
|
+
from pathlib import Path, PureWindowsPath
|
|
21
|
+
|
|
22
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
23
|
+
|
|
24
|
+
from flat_packager.archive import ARCHIVE_KIND, emit_json_line
|
|
25
|
+
from flat_packager.unpack import join_component, restore_archive, windows_unsafe_reason
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def write_single_file_archive(archive: Path, rel_path: str, content: bytes) -> None:
|
|
29
|
+
with archive.open("w", encoding="utf-8", newline="\n") as handle:
|
|
30
|
+
emit_json_line(handle, {"type": ARCHIVE_KIND, "version": 1})
|
|
31
|
+
emit_json_line(
|
|
32
|
+
handle,
|
|
33
|
+
{
|
|
34
|
+
"type": "file",
|
|
35
|
+
"path": rel_path,
|
|
36
|
+
"mode": 0o644,
|
|
37
|
+
"size": len(content),
|
|
38
|
+
"sha256": hashlib.sha256(content).hexdigest(),
|
|
39
|
+
"encoding": "base64",
|
|
40
|
+
"content": base64.b64encode(content).decode("ascii"),
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
emit_json_line(handle, {"type": "end", "entries": 1, "files": 1})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@unittest.skipUnless(os.name == "nt", "Windows path semantics")
|
|
47
|
+
class WindowsRestorePathTests(unittest.TestCase):
|
|
48
|
+
def setUp(self) -> None:
|
|
49
|
+
self.work_dir = Path(tempfile.mkdtemp(prefix="flat-packager-win-"))
|
|
50
|
+
self.original_cwd = Path.cwd()
|
|
51
|
+
|
|
52
|
+
def tearDown(self) -> None:
|
|
53
|
+
os.chdir(self.original_cwd)
|
|
54
|
+
shutil.rmtree(self.work_dir, ignore_errors=True)
|
|
55
|
+
|
|
56
|
+
def restore(self, archive: Path, output: Path) -> Exception | None:
|
|
57
|
+
try:
|
|
58
|
+
restore_archive(
|
|
59
|
+
archive_path=archive,
|
|
60
|
+
output_dir=output,
|
|
61
|
+
overwrite=False,
|
|
62
|
+
verify_only=False,
|
|
63
|
+
no_symlinks=False,
|
|
64
|
+
)
|
|
65
|
+
except (ValueError, OSError) as exc:
|
|
66
|
+
return exc
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
def assert_drive_relative_path_does_not_escape(self, template: str) -> None:
|
|
70
|
+
# A drive-relative path ("D:x") only escapes when it names a different
|
|
71
|
+
# drive than the output directory, so put the "outside" directory and
|
|
72
|
+
# the current directory on the checkout's drive and restore to TEMP.
|
|
73
|
+
outside = Path(tempfile.mkdtemp(prefix="flat-packager-outside-", dir=self.original_cwd))
|
|
74
|
+
self.addCleanup(shutil.rmtree, outside, True)
|
|
75
|
+
if outside.drive.lower() == self.work_dir.drive.lower():
|
|
76
|
+
self.skipTest(f"needs two drives; TEMP and checkout are both on {outside.drive}")
|
|
77
|
+
os.chdir(outside)
|
|
78
|
+
|
|
79
|
+
rel_path = template.format(drive=outside.drive)
|
|
80
|
+
archive = self.work_dir / "archive.flat.txt"
|
|
81
|
+
output = self.work_dir / "output"
|
|
82
|
+
write_single_file_archive(archive, rel_path, b"escaped\n")
|
|
83
|
+
|
|
84
|
+
error = self.restore(archive, output)
|
|
85
|
+
|
|
86
|
+
escaped = sorted(p.name for p in outside.iterdir())
|
|
87
|
+
self.assertEqual(
|
|
88
|
+
escaped,
|
|
89
|
+
[],
|
|
90
|
+
f"archive path {rel_path!r} wrote {escaped} into {outside} "
|
|
91
|
+
f"(outside the output directory {output}); restore error: {error!r}",
|
|
92
|
+
)
|
|
93
|
+
self.assertIsInstance(error, ValueError, f"{rel_path!r} was not rejected")
|
|
94
|
+
self.assertIn("unsafe archive path on Windows", str(error))
|
|
95
|
+
self.assertFalse(output.exists())
|
|
96
|
+
|
|
97
|
+
def test_drive_relative_path_does_not_escape(self) -> None:
|
|
98
|
+
self.assert_drive_relative_path_does_not_escape("{drive}escaped.txt")
|
|
99
|
+
|
|
100
|
+
def test_nested_drive_relative_path_does_not_escape(self) -> None:
|
|
101
|
+
self.assert_drive_relative_path_does_not_escape("sub/{drive}escaped.txt")
|
|
102
|
+
|
|
103
|
+
def assert_rejected(self, rel_path: str) -> None:
|
|
104
|
+
# A fresh directory per call: subtests must not share an output dir.
|
|
105
|
+
case_dir = Path(tempfile.mkdtemp(prefix="case-", dir=self.work_dir))
|
|
106
|
+
archive = case_dir / "archive.flat.txt"
|
|
107
|
+
output = case_dir / "output"
|
|
108
|
+
write_single_file_archive(archive, rel_path, b"data\n")
|
|
109
|
+
error = self.restore(archive, output)
|
|
110
|
+
self.assertIsInstance(
|
|
111
|
+
error, ValueError, f"{rel_path!r} was not rejected on Windows (error: {error!r})"
|
|
112
|
+
)
|
|
113
|
+
self.assertFalse(output.exists())
|
|
114
|
+
|
|
115
|
+
def test_alternate_data_stream_is_rejected(self) -> None:
|
|
116
|
+
self.assert_rejected("file.txt:hidden")
|
|
117
|
+
|
|
118
|
+
def test_reserved_device_names_are_rejected(self) -> None:
|
|
119
|
+
for rel_path in ("NUL", "nul.txt", "aux.py", "COM1/x.txt", "sub/LPT1", "CONIN$"):
|
|
120
|
+
with self.subTest(path=rel_path):
|
|
121
|
+
self.assert_rejected(rel_path)
|
|
122
|
+
|
|
123
|
+
def test_trailing_dot_or_space_is_rejected(self) -> None:
|
|
124
|
+
for rel_path in ("name.", "name ", "dir./x.txt", "dir /x.txt"):
|
|
125
|
+
with self.subTest(path=rel_path):
|
|
126
|
+
self.assert_rejected(rel_path)
|
|
127
|
+
|
|
128
|
+
def test_ordinary_names_still_restore(self) -> None:
|
|
129
|
+
archive = self.work_dir / "archive.flat.txt"
|
|
130
|
+
output = self.work_dir / "output"
|
|
131
|
+
write_single_file_archive(archive, "src/console.py", b"print(1)\n")
|
|
132
|
+
self.assertIsNone(self.restore(archive, output))
|
|
133
|
+
self.assertEqual((output / "src" / "console.py").read_bytes(), b"print(1)\n")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class WindowsNameRulesTests(unittest.TestCase):
|
|
137
|
+
"""Platform-independent checks of the Windows rules, so every CI job covers them."""
|
|
138
|
+
|
|
139
|
+
def test_unsafe_names(self) -> None:
|
|
140
|
+
for part, reason in (
|
|
141
|
+
("D:escaped.txt", "forbidden character"),
|
|
142
|
+
("file.txt:hidden", "forbidden character"),
|
|
143
|
+
("a<b", "forbidden character"),
|
|
144
|
+
("tab\tname", "forbidden character"),
|
|
145
|
+
("NUL", "reserved device name"),
|
|
146
|
+
("nul.txt", "reserved device name"),
|
|
147
|
+
("aux.tar.gz", "reserved device name"),
|
|
148
|
+
("COM1", "reserved device name"),
|
|
149
|
+
("lpt9.log", "reserved device name"),
|
|
150
|
+
("CONIN$", "reserved device name"),
|
|
151
|
+
("COM\u00b9", "reserved device name"),
|
|
152
|
+
("name.", "trailing dot or space"),
|
|
153
|
+
("name ", "trailing dot or space"),
|
|
154
|
+
):
|
|
155
|
+
with self.subTest(part=part):
|
|
156
|
+
found = windows_unsafe_reason(part)
|
|
157
|
+
self.assertIsNotNone(found)
|
|
158
|
+
assert found is not None
|
|
159
|
+
self.assertIn(reason, found)
|
|
160
|
+
|
|
161
|
+
def test_safe_names(self) -> None:
|
|
162
|
+
for part in ("console.py", "nullable", "COM10", "auxiliary", ".gitignore", "a.b.c", "..x"):
|
|
163
|
+
with self.subTest(part=part):
|
|
164
|
+
self.assertIsNone(windows_unsafe_reason(part))
|
|
165
|
+
|
|
166
|
+
def test_join_component_refuses_to_leave_parent(self) -> None:
|
|
167
|
+
root = PureWindowsPath(r"C:\out")
|
|
168
|
+
for part in ("D:x", "C:x", r"\\server\share", "/etc"):
|
|
169
|
+
with self.subTest(part=part), self.assertRaises(ValueError):
|
|
170
|
+
join_component(root, part) # type: ignore[arg-type]
|
|
171
|
+
self.assertEqual(join_component(root, "sub"), PureWindowsPath(r"C:\out\sub")) # type: ignore[arg-type]
|
|
172
|
+
|
|
173
|
+
@unittest.skipIf(os.name == "nt", "colons are legal in POSIX names only")
|
|
174
|
+
def test_colon_names_still_restore_on_posix(self) -> None:
|
|
175
|
+
work_dir = Path(tempfile.mkdtemp(prefix="flat-packager-colon-"))
|
|
176
|
+
self.addCleanup(shutil.rmtree, work_dir, True)
|
|
177
|
+
archive = work_dir / "archive.flat.txt"
|
|
178
|
+
output = work_dir / "output"
|
|
179
|
+
write_single_file_archive(archive, "logs/2026-12-01T10:00.log", b"ok\n")
|
|
180
|
+
restore_archive(
|
|
181
|
+
archive_path=archive,
|
|
182
|
+
output_dir=output,
|
|
183
|
+
overwrite=False,
|
|
184
|
+
verify_only=False,
|
|
185
|
+
no_symlinks=False,
|
|
186
|
+
)
|
|
187
|
+
self.assertEqual((output / "logs" / "2026-12-01T10:00.log").read_bytes(), b"ok\n")
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if __name__ == "__main__":
|
|
191
|
+
unittest.main()
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|