devklean 1.1.0__tar.gz → 1.2.0__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.
- {devklean-1.1.0 → devklean-1.2.0}/CHANGELOG.md +22 -1
- {devklean-1.1.0 → devklean-1.2.0}/PKG-INFO +11 -3
- {devklean-1.1.0 → devklean-1.2.0}/README.md +8 -1
- {devklean-1.1.0 → devklean-1.2.0}/pyproject.toml +1 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/__init__.py +2 -2
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/_version.py +1 -1
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/metadata.py +26 -3
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/trash.py +51 -4
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/models.py +22 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/text.py +7 -1
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_deletion.py +76 -8
- devklean-1.2.0/tests/test_interruption.py +178 -0
- {devklean-1.1.0 → devklean-1.2.0}/.gitignore +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/LICENSE +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/__main__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/analyze.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/clean.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/common.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/doctor.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/explain.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/history.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/restore.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/commands/scan.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/confirmation.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/dispatcher.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/main.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/cli/parser.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/config/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/config/defaults.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/config/manager.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/config/models.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/config/paths.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/config/targets.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/compression.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/history.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/integrity.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/paths.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/deletion/safety.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/formatting.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/logging_setup.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/base.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/console.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/history_payload.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/json.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/scan_payload.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/sorting.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/output/theme.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/scanner/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/scanner/filters.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/scanner/scanner.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/signatures/__init__.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/signatures/analysis.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/signatures/health.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/signatures/registry.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/signatures/staleness.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/signatures/structural.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/src/devklean/tui.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/benchmark_scanner.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/conftest.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_analyze_command.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_clean_flow.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_cli_parser.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_compression.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_config.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_config_precedence.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_confirmation.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_console.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_doctor.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_dry_run.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_explain_command.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_formatting.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_history.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_integration.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_integrity.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_json_output.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_logging.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_main_signal.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_models.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_output_sorting.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_packaging.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_perf_scan.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_restore.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_safety.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_scan_json_cli.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_scan_permissions.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_scan_settings.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_scanner.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_signatures_health.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_signatures_registry.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_signatures_staleness.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_signatures_structural.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_text_renderer.py +0 -0
- {devklean-1.1.0 → devklean-1.2.0}/tests/test_windows_guard.py +0 -0
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0] - 2026-11-29
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Python 3.13 is now tested in CI (Linux, macOS, Windows) and declared via
|
|
15
|
+
the `Programming Language :: Python :: 3.13` classifier. No code changes
|
|
16
|
+
were needed; the universal `py3-none-any` wheel is unchanged.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Compress-before-trash where the archive reaches trash but the original
|
|
21
|
+
directory cannot be removed is now a distinct `partial` outcome on
|
|
22
|
+
`DeleteResult` (not success, not plain failure). The trashed archive is
|
|
23
|
+
recorded in metadata with `status = "partial"` (schema version 6) so
|
|
24
|
+
`history` and `doctor` can see it; CLI output warns plainly instead of
|
|
25
|
+
reporting a generic failure.
|
|
26
|
+
|
|
27
|
+
## [1.1.0] - 2026-07-09
|
|
28
|
+
|
|
10
29
|
### Added
|
|
11
30
|
|
|
12
31
|
- **`analyze [PATH]`** — scan for cleanable directories and cross-reference
|
|
@@ -134,7 +153,9 @@ First public pre-release.
|
|
|
134
153
|
per-target sizing.
|
|
135
154
|
- **Packaging** — distributable via `pip`/`pipx`; MIT licensed.
|
|
136
155
|
|
|
137
|
-
[Unreleased]: https://github.com/smurftyy/devklean/compare/v1.0
|
|
156
|
+
[Unreleased]: https://github.com/smurftyy/devklean/compare/v1.2.0...HEAD
|
|
157
|
+
[1.2.0]: https://github.com/smurftyy/devklean/compare/v1.1.0...v1.2.0
|
|
158
|
+
[1.1.0]: https://github.com/smurftyy/devklean/compare/v1.0.2...v1.1.0
|
|
138
159
|
[1.0.2]: https://github.com/smurftyy/devklean/compare/v1.0.1...v1.0.2
|
|
139
160
|
[1.0.1]: https://github.com/smurftyy/devklean/compare/v1.0.0...v1.0.1
|
|
140
161
|
[1.0.0]: https://github.com/smurftyy/devklean/compare/v0.1.0...v1.0.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: devklean
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Clean up common development artifacts (node_modules, .venv, caches) to reclaim disk space
|
|
5
5
|
Project-URL: Homepage, https://github.com/smurftyy/devklean
|
|
6
6
|
Project-URL: Repository, https://github.com/smurftyy/devklean
|
|
@@ -21,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
25
|
Classifier: Topic :: System :: Filesystems
|
|
25
26
|
Classifier: Topic :: Utilities
|
|
26
27
|
Requires-Python: >=3.8
|
|
@@ -39,11 +40,13 @@ Requires-Dist: zstandard>=0.21; extra == 'zstd'
|
|
|
39
40
|
Description-Content-Type: text/markdown
|
|
40
41
|
|
|
41
42
|
# devklean
|
|
43
|
+
🧹 The ultimate developer cleanup utility.
|
|
42
44
|
|
|
43
45
|
[](https://github.com/smurftyy/devklean/actions/workflows/ci.yml)
|
|
44
46
|
[](https://pypi.org/project/devklean/)
|
|
45
47
|
[](https://pypi.org/project/devklean/)
|
|
46
48
|
[](https://github.com/smurftyy/devklean/blob/main/LICENSE)
|
|
49
|
+
[](https://devklean.smurftyy.dev)
|
|
47
50
|
|
|
48
51
|
**Reclaim disk space by safely cleaning up development artifacts** — `node_modules`, `.venv`, build caches, and other regenerable directories — with a trash-backed safety net so nothing is ever lost to a typo.
|
|
49
52
|
|
|
@@ -338,7 +341,12 @@ Run `devklean doctor` to detect and remove corrupt metadata records.
|
|
|
338
341
|
|
|
339
342
|
## Contributing
|
|
340
343
|
|
|
341
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
344
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) — pull requests target the `dev` branch.
|
|
345
|
+
Bug reports and PRs are welcome; [`good first issue`](https://github.com/smurftyy/devklean/labels/good%20first%20issue)
|
|
346
|
+
is a good place to start. Questions and ideas go in [Discussions](https://github.com/smurftyy/devklean/discussions).
|
|
347
|
+
|
|
348
|
+
This project follows a [Code of Conduct](CODE_OF_CONDUCT.md). To report a security
|
|
349
|
+
issue, see [SECURITY.md](SECURITY.md).
|
|
342
350
|
|
|
343
351
|
## License
|
|
344
352
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# devklean
|
|
2
|
+
🧹 The ultimate developer cleanup utility.
|
|
2
3
|
|
|
3
4
|
[](https://github.com/smurftyy/devklean/actions/workflows/ci.yml)
|
|
4
5
|
[](https://pypi.org/project/devklean/)
|
|
5
6
|
[](https://pypi.org/project/devklean/)
|
|
6
7
|
[](https://github.com/smurftyy/devklean/blob/main/LICENSE)
|
|
8
|
+
[](https://devklean.smurftyy.dev)
|
|
7
9
|
|
|
8
10
|
**Reclaim disk space by safely cleaning up development artifacts** — `node_modules`, `.venv`, build caches, and other regenerable directories — with a trash-backed safety net so nothing is ever lost to a typo.
|
|
9
11
|
|
|
@@ -298,7 +300,12 @@ Run `devklean doctor` to detect and remove corrupt metadata records.
|
|
|
298
300
|
|
|
299
301
|
## Contributing
|
|
300
302
|
|
|
301
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
303
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) — pull requests target the `dev` branch.
|
|
304
|
+
Bug reports and PRs are welcome; [`good first issue`](https://github.com/smurftyy/devklean/labels/good%20first%20issue)
|
|
305
|
+
is a good place to start. Questions and ideas go in [Discussions](https://github.com/smurftyy/devklean/discussions).
|
|
306
|
+
|
|
307
|
+
This project follows a [Code of Conduct](CODE_OF_CONDUCT.md). To report a security
|
|
308
|
+
issue, see [SECURITY.md](SECURITY.md).
|
|
302
309
|
|
|
303
310
|
## License
|
|
304
311
|
|
|
@@ -26,6 +26,7 @@ classifiers = [
|
|
|
26
26
|
"Programming Language :: Python :: 3.10",
|
|
27
27
|
"Programming Language :: Python :: 3.11",
|
|
28
28
|
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
29
30
|
"Topic :: System :: Filesystems",
|
|
30
31
|
"Topic :: Utilities",
|
|
31
32
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""devklean — scan and remove node_modules / venvs to reclaim disk space."""
|
|
2
2
|
|
|
3
3
|
from devklean._version import __version__
|
|
4
|
-
from devklean.models import CleanableItem, DeleteFailure, DeleteResult
|
|
4
|
+
from devklean.models import CleanableItem, DeleteFailure, DeleteResult, PartialDeletion
|
|
5
5
|
|
|
6
|
-
__all__ = ["CleanableItem", "DeleteFailure", "DeleteResult", "__version__"]
|
|
6
|
+
__all__ = ["CleanableItem", "DeleteFailure", "DeleteResult", "PartialDeletion", "__version__"]
|
|
@@ -16,7 +16,13 @@ from devklean.models import CleanableItem, DeleteResult
|
|
|
16
16
|
TRASH_STRATEGY = "trash"
|
|
17
17
|
# Bumped for the archive dict gaining compressed/original_size/compressed_size;
|
|
18
18
|
# the new fields are optional on read so schema_version <= 4 records still parse.
|
|
19
|
-
|
|
19
|
+
# Version 6 adds the top-level `status` field ("deleted" vs "partial") so a
|
|
20
|
+
# compress-before-trash run whose archive reached trash but whose original
|
|
21
|
+
# could not be removed stays visible to history/doctor instead of vanishing.
|
|
22
|
+
SCHEMA_VERSION = 6
|
|
23
|
+
|
|
24
|
+
STATUS_DELETED = "deleted"
|
|
25
|
+
STATUS_PARTIAL = "partial"
|
|
20
26
|
|
|
21
27
|
|
|
22
28
|
@dataclass(frozen=True)
|
|
@@ -67,6 +73,7 @@ class DeletionMetadataRecord:
|
|
|
67
73
|
strategy: str
|
|
68
74
|
item: DeletionMetadataItem
|
|
69
75
|
archive: DeletionArchive | None = None
|
|
76
|
+
status: str = STATUS_DELETED
|
|
70
77
|
|
|
71
78
|
def to_dict(self) -> dict[str, object]:
|
|
72
79
|
payload = {
|
|
@@ -78,6 +85,7 @@ class DeletionMetadataRecord:
|
|
|
78
85
|
"strategy": self.strategy,
|
|
79
86
|
},
|
|
80
87
|
"item": self.item.to_dict(),
|
|
88
|
+
"status": self.status,
|
|
81
89
|
}
|
|
82
90
|
if self.archive is not None:
|
|
83
91
|
payload["archive"] = self.archive.to_dict()
|
|
@@ -127,6 +135,11 @@ def _parse_record(data: dict[str, object]) -> DeletionMetadataRecord:
|
|
|
127
135
|
# version is accepted as-is; there are no migrations yet.
|
|
128
136
|
schema_version = data.get("schema_version", 1)
|
|
129
137
|
|
|
138
|
+
# `status` postdates schema_version 5; absence means a legacy "deleted"
|
|
139
|
+
# record, so absence is not an error. Unknown values are rejected as
|
|
140
|
+
# corrupt so doctor can flag them rather than silently misreporting.
|
|
141
|
+
status = data.get("status", STATUS_DELETED)
|
|
142
|
+
|
|
130
143
|
if not (
|
|
131
144
|
isinstance(deletion_id, str)
|
|
132
145
|
and (run_id is None or isinstance(run_id, str))
|
|
@@ -171,6 +184,9 @@ def _parse_record(data: dict[str, object]) -> DeletionMetadataRecord:
|
|
|
171
184
|
if strategy != TRASH_STRATEGY:
|
|
172
185
|
raise ValueError(f"unrecognized strategy {strategy!r}")
|
|
173
186
|
|
|
187
|
+
if not isinstance(status, str) or status not in (STATUS_DELETED, STATUS_PARTIAL):
|
|
188
|
+
raise ValueError(f"unrecognized status {status!r}")
|
|
189
|
+
|
|
174
190
|
return DeletionMetadataRecord(
|
|
175
191
|
schema_version=schema_version,
|
|
176
192
|
deletion_id=deletion_id,
|
|
@@ -183,6 +199,7 @@ def _parse_record(data: dict[str, object]) -> DeletionMetadataRecord:
|
|
|
183
199
|
size=size,
|
|
184
200
|
),
|
|
185
201
|
archive=archive,
|
|
202
|
+
status=status,
|
|
186
203
|
)
|
|
187
204
|
|
|
188
205
|
|
|
@@ -240,7 +257,8 @@ class MetadataManager:
|
|
|
240
257
|
archives: Mapping[str, DeletionArchive] | None = None,
|
|
241
258
|
) -> None:
|
|
242
259
|
deleted_paths = set(result.deleted)
|
|
243
|
-
|
|
260
|
+
partial_paths = {p.path for p in result.partial}
|
|
261
|
+
if not deleted_paths and not partial_paths:
|
|
244
262
|
return
|
|
245
263
|
|
|
246
264
|
self._storage_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -250,7 +268,11 @@ class MetadataManager:
|
|
|
250
268
|
archives = archives or {}
|
|
251
269
|
|
|
252
270
|
for item in items:
|
|
253
|
-
if item.path
|
|
271
|
+
if item.path in deleted_paths:
|
|
272
|
+
status = STATUS_DELETED
|
|
273
|
+
elif item.path in partial_paths:
|
|
274
|
+
status = STATUS_PARTIAL
|
|
275
|
+
else:
|
|
254
276
|
continue
|
|
255
277
|
|
|
256
278
|
archive = archives.get(item.path)
|
|
@@ -267,6 +289,7 @@ class MetadataManager:
|
|
|
267
289
|
size=item.size,
|
|
268
290
|
),
|
|
269
291
|
archive=archive,
|
|
292
|
+
status=status,
|
|
270
293
|
)
|
|
271
294
|
stamp = record.timestamp.replace(":", "").replace("+00:00", "Z")
|
|
272
295
|
filename = f"{stamp}_{record.deletion_id}.json"
|
|
@@ -15,7 +15,7 @@ from devklean.deletion.compression import (
|
|
|
15
15
|
from devklean.deletion.metadata import TRASH_STRATEGY, DeletionArchive, MetadataManager
|
|
16
16
|
from devklean.deletion.safety import SafetyValidator
|
|
17
17
|
from devklean.logging_setup import get_logger
|
|
18
|
-
from devklean.models import CleanableItem, DeleteFailure, DeleteResult
|
|
18
|
+
from devklean.models import CleanableItem, DeleteFailure, DeleteResult, PartialDeletion
|
|
19
19
|
|
|
20
20
|
# The single deletion backend is the native OS trash (Recycle Bin on Windows,
|
|
21
21
|
# ~/.Trash on macOS, the freedesktop trash on Linux) via send2trash. The name
|
|
@@ -23,6 +23,19 @@ from devklean.models import CleanableItem, DeleteFailure, DeleteResult
|
|
|
23
23
|
STRATEGY_NAME = TRASH_STRATEGY
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
class OriginalCleanupError(OSError):
|
|
27
|
+
"""Archive reached trash but the original directory could not be removed.
|
|
28
|
+
|
|
29
|
+
Carries the trashed archive so callers can record it instead of losing
|
|
30
|
+
it in a plain failure. No data is lost: the recoverable copy is in trash,
|
|
31
|
+
the source is still on disk.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, message: str, archive: DeletionArchive) -> None:
|
|
35
|
+
super().__init__(message)
|
|
36
|
+
self.archive = archive
|
|
37
|
+
|
|
38
|
+
|
|
26
39
|
def delete_items(
|
|
27
40
|
items: Sequence[CleanableItem],
|
|
28
41
|
total_size: int,
|
|
@@ -73,6 +86,7 @@ def delete_items(
|
|
|
73
86
|
|
|
74
87
|
deleted: list[str] = []
|
|
75
88
|
failures: list[DeleteFailure] = []
|
|
89
|
+
partials: list[PartialDeletion] = []
|
|
76
90
|
archives: dict[str, DeletionArchive] = {}
|
|
77
91
|
for item in safe:
|
|
78
92
|
try:
|
|
@@ -85,6 +99,21 @@ def delete_items(
|
|
|
85
99
|
if archive is not None:
|
|
86
100
|
archives[item.path] = archive
|
|
87
101
|
deleted.append(item.path)
|
|
102
|
+
except OriginalCleanupError as exc:
|
|
103
|
+
# Archive is already safe in trash; the original is still on disk.
|
|
104
|
+
# A distinct outcome, not success nor plain failure, so history
|
|
105
|
+
# and doctor can see the trashed archive.
|
|
106
|
+
archives[item.path] = exc.archive
|
|
107
|
+
partials.append(
|
|
108
|
+
PartialDeletion(
|
|
109
|
+
path=item.path,
|
|
110
|
+
error=str(exc),
|
|
111
|
+
archive_path=exc.archive.path,
|
|
112
|
+
archive_format=exc.archive.format,
|
|
113
|
+
original_size=exc.archive.original_size,
|
|
114
|
+
compressed_size=exc.archive.compressed_size,
|
|
115
|
+
)
|
|
116
|
+
)
|
|
88
117
|
except (OSError, CompressionVerificationError) as exc:
|
|
89
118
|
# TrashPermissionError subclasses OSError; ENOENT/EACCES and
|
|
90
119
|
# platform-specific failures surface here too, alongside
|
|
@@ -97,17 +126,27 @@ def delete_items(
|
|
|
97
126
|
deleted=tuple(deleted),
|
|
98
127
|
failed=tuple(failures) + blocked_failures,
|
|
99
128
|
total_size=safe_total,
|
|
129
|
+
partial=tuple(partials),
|
|
100
130
|
)
|
|
101
131
|
|
|
102
132
|
for path in result.deleted:
|
|
103
133
|
logger.info("deleted strategy=%s path=%s", STRATEGY_NAME, path)
|
|
134
|
+
for partial in result.partial:
|
|
135
|
+
logger.warning(
|
|
136
|
+
"partial delete strategy=%s path=%s archive=%s error=%s",
|
|
137
|
+
STRATEGY_NAME,
|
|
138
|
+
partial.path,
|
|
139
|
+
partial.archive_path,
|
|
140
|
+
partial.error,
|
|
141
|
+
)
|
|
104
142
|
for failure in result.failed:
|
|
105
143
|
logger.warning("delete failed path=%s error=%s", failure.path, failure.error)
|
|
106
144
|
logger.info(
|
|
107
|
-
"deletion summary strategy=%s deleted=%d failed=%d size=%d compressed=%d",
|
|
145
|
+
"deletion summary strategy=%s deleted=%d failed=%d partial=%d size=%d compressed=%d",
|
|
108
146
|
STRATEGY_NAME,
|
|
109
147
|
result.deleted_count,
|
|
110
148
|
result.failed_count,
|
|
149
|
+
result.partial_count,
|
|
111
150
|
result.total_size,
|
|
112
151
|
len(archives),
|
|
113
152
|
)
|
|
@@ -167,9 +206,17 @@ def _send_to_trash(
|
|
|
167
206
|
try:
|
|
168
207
|
shutil.rmtree(source)
|
|
169
208
|
except OSError as exc:
|
|
170
|
-
|
|
209
|
+
archive = DeletionArchive(
|
|
210
|
+
path=str(result.archive_path),
|
|
211
|
+
format=result.format,
|
|
212
|
+
compressed=True,
|
|
213
|
+
original_size=result.original_size,
|
|
214
|
+
compressed_size=compressed_size,
|
|
215
|
+
)
|
|
216
|
+
raise OriginalCleanupError(
|
|
171
217
|
f"compressed archive was trashed, but the original directory {source} "
|
|
172
|
-
f"could not be removed ({exc}); remove it manually to reclaim the disk space"
|
|
218
|
+
f"could not be removed ({exc}); remove it manually to reclaim the disk space",
|
|
219
|
+
archive,
|
|
173
220
|
) from exc
|
|
174
221
|
|
|
175
222
|
return DeletionArchive(
|
|
@@ -19,11 +19,29 @@ class DeleteFailure:
|
|
|
19
19
|
error: str
|
|
20
20
|
|
|
21
21
|
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class PartialDeletion:
|
|
24
|
+
"""Archive trashed but original directory could not be removed.
|
|
25
|
+
|
|
26
|
+
Distinct from success (original gone) and failure (nothing trashed):
|
|
27
|
+
the compressed archive genuinely exists in trash, the source is still
|
|
28
|
+
on disk and must be removed manually.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
path: str
|
|
32
|
+
error: str
|
|
33
|
+
archive_path: str
|
|
34
|
+
archive_format: str = "gzip"
|
|
35
|
+
original_size: int | None = None
|
|
36
|
+
compressed_size: int | None = None
|
|
37
|
+
|
|
38
|
+
|
|
22
39
|
@dataclass(frozen=True)
|
|
23
40
|
class DeleteResult:
|
|
24
41
|
deleted: tuple[str, ...]
|
|
25
42
|
failed: tuple[DeleteFailure, ...]
|
|
26
43
|
total_size: int
|
|
44
|
+
partial: tuple[PartialDeletion, ...] = ()
|
|
27
45
|
|
|
28
46
|
@property
|
|
29
47
|
def deleted_count(self) -> int:
|
|
@@ -32,3 +50,7 @@ class DeleteResult:
|
|
|
32
50
|
@property
|
|
33
51
|
def failed_count(self) -> int:
|
|
34
52
|
return len(self.failed)
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def partial_count(self) -> int:
|
|
56
|
+
return len(self.partial)
|
|
@@ -6,7 +6,7 @@ from devklean.deletion.history import HistoryOperation
|
|
|
6
6
|
from devklean.deletion.integrity import IntegrityReport
|
|
7
7
|
from devklean.formatting import format_size, format_timestamp, truncate
|
|
8
8
|
from devklean.models import CleanableItem, DeleteResult
|
|
9
|
-
from devklean.output.console import SYM_ERROR, SYM_SUCCESS, Console
|
|
9
|
+
from devklean.output.console import SYM_ERROR, SYM_SUCCESS, SYM_WARNING, Console
|
|
10
10
|
from devklean.output.sorting import items_by_size_desc
|
|
11
11
|
from devklean.signatures import ArtifactSignature
|
|
12
12
|
from devklean.signatures.analysis import AnalysisReport
|
|
@@ -86,6 +86,8 @@ class TextRenderer:
|
|
|
86
86
|
self._println()
|
|
87
87
|
for path in result.deleted:
|
|
88
88
|
self._println(f" {c.paint(SYM_SUCCESS, 'success')} {c.paint(path, 'detail')}")
|
|
89
|
+
for partial in result.partial:
|
|
90
|
+
self._println(f" {c.paint(SYM_WARNING, 'warning')} {partial.path} — {partial.error}")
|
|
89
91
|
for failure in result.failed:
|
|
90
92
|
self._println(f" {c.paint(SYM_ERROR, 'error')} {failure.path} — {failure.error}")
|
|
91
93
|
|
|
@@ -95,6 +97,10 @@ class TextRenderer:
|
|
|
95
97
|
self._console.success(
|
|
96
98
|
c.paint(f"Cleaned {deleted} {word}, freed ~{format_size(result.total_size)}.", "bold")
|
|
97
99
|
)
|
|
100
|
+
if result.partial_count:
|
|
101
|
+
self._console.warning(
|
|
102
|
+
f"{result.partial_count} partial: archive in trash, original still on disk."
|
|
103
|
+
)
|
|
98
104
|
if result.failed_count:
|
|
99
105
|
self._console.error(f"{result.failed_count} failed.")
|
|
100
106
|
self._println()
|
|
@@ -184,12 +184,14 @@ def test_delete_items_surfaces_error_when_original_removal_fails_after_trash(
|
|
|
184
184
|
[item], item.size, metadata_manager=manager, compress=True, compress_min_size=0
|
|
185
185
|
)
|
|
186
186
|
|
|
187
|
-
#
|
|
187
|
+
# Distinct outcome: not success, not plain failure — partial.
|
|
188
188
|
assert result.deleted == ()
|
|
189
|
-
assert
|
|
190
|
-
assert result.
|
|
189
|
+
assert result.failed == ()
|
|
190
|
+
assert len(result.partial) == 1
|
|
191
|
+
assert result.partial[0].path == str(source)
|
|
192
|
+
assert result.partial_count == 1
|
|
191
193
|
|
|
192
|
-
error = result.
|
|
194
|
+
error = result.partial[0].error
|
|
193
195
|
# Distinct from an ordinary failure: says the archive made it to trash...
|
|
194
196
|
assert "compressed archive was trashed" in error
|
|
195
197
|
# ...names the actual reason (proves {exc} was interpolated, not hardcoded)...
|
|
@@ -207,8 +209,73 @@ def test_delete_items_surfaces_error_when_original_removal_fails_after_trash(
|
|
|
207
209
|
assert source.exists()
|
|
208
210
|
assert (source / "a.txt").exists()
|
|
209
211
|
|
|
210
|
-
# A
|
|
211
|
-
|
|
212
|
+
# A partial item is recorded (status=partial) so history/doctor can see
|
|
213
|
+
# the trashed archive, unlike a plain failure.
|
|
214
|
+
records = manager.load_records()
|
|
215
|
+
assert len(records.records) == 1
|
|
216
|
+
stored = records.records[0]
|
|
217
|
+
assert stored.record.item.original_path == str(source)
|
|
218
|
+
assert stored.record.status == "partial"
|
|
219
|
+
assert stored.record.archive is not None
|
|
220
|
+
assert stored.record.archive.format == "gzip"
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def test_delete_items_compress_path_calls_happen_in_safety_order(
|
|
224
|
+
tmp_path: Path, fake_trash, monkeypatch
|
|
225
|
+
) -> None:
|
|
226
|
+
"""Pins the exact call order of the compress-before-trash contract:
|
|
227
|
+
compress, then verify, then send2trash, then (only now) remove the
|
|
228
|
+
original. The other tests above prove the *symptom* (a failure at each
|
|
229
|
+
step leaves the source alone); this one asserts the *cause* directly, so
|
|
230
|
+
a refactor that reorders these four calls fails immediately here even if
|
|
231
|
+
it doesn't happen to break any single failure-injection test. This is
|
|
232
|
+
precisely the invariant PR #12 violated: it called rmtree(source) before
|
|
233
|
+
send2trash ran at all.
|
|
234
|
+
"""
|
|
235
|
+
source = tmp_path / "workspace" / "node_modules"
|
|
236
|
+
source.mkdir(parents=True)
|
|
237
|
+
(source / "a.txt").write_text("A" * 2048, encoding="utf-8")
|
|
238
|
+
original_size = sum(f.stat().st_size for f in source.rglob("*") if f.is_file())
|
|
239
|
+
|
|
240
|
+
calls: list[str] = []
|
|
241
|
+
|
|
242
|
+
import devklean.deletion.trash as trash_module
|
|
243
|
+
|
|
244
|
+
real_compress_path = trash_module.compress_path
|
|
245
|
+
real_verify_archive = trash_module.verify_archive
|
|
246
|
+
real_send2trash = trash_module.send2trash
|
|
247
|
+
real_rmtree = trash_module.shutil.rmtree
|
|
248
|
+
|
|
249
|
+
def _compress_path(*args, **kwargs):
|
|
250
|
+
calls.append("compress")
|
|
251
|
+
return real_compress_path(*args, **kwargs)
|
|
252
|
+
|
|
253
|
+
def _verify_archive(*args, **kwargs):
|
|
254
|
+
calls.append("verify")
|
|
255
|
+
return real_verify_archive(*args, **kwargs)
|
|
256
|
+
|
|
257
|
+
def _send2trash(*args, **kwargs):
|
|
258
|
+
calls.append("send2trash")
|
|
259
|
+
return real_send2trash(*args, **kwargs)
|
|
260
|
+
|
|
261
|
+
def _rmtree(*args, **kwargs):
|
|
262
|
+
calls.append("rmtree")
|
|
263
|
+
return real_rmtree(*args, **kwargs)
|
|
264
|
+
|
|
265
|
+
monkeypatch.setattr(trash_module, "compress_path", _compress_path)
|
|
266
|
+
monkeypatch.setattr(trash_module, "verify_archive", _verify_archive)
|
|
267
|
+
monkeypatch.setattr(trash_module, "send2trash", _send2trash)
|
|
268
|
+
monkeypatch.setattr(trash_module.shutil, "rmtree", _rmtree)
|
|
269
|
+
|
|
270
|
+
item = CleanableItem(str(source), "node_modules", original_size, "Node.js")
|
|
271
|
+
manager = MetadataManager(storage_dir=tmp_path / "m")
|
|
272
|
+
|
|
273
|
+
result = delete_items(
|
|
274
|
+
[item], item.size, metadata_manager=manager, compress=True, compress_min_size=0
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
assert result.deleted == (str(source),)
|
|
278
|
+
assert calls == ["compress", "verify", "send2trash", "rmtree"]
|
|
212
279
|
|
|
213
280
|
|
|
214
281
|
def test_delete_items_does_not_call_send2trash_on_dry_run(tmp_path: Path, fake_trash) -> None:
|
|
@@ -356,12 +423,13 @@ def test_delete_items_records_only_successes(tmp_path: Path, monkeypatch) -> Non
|
|
|
356
423
|
payload = json.loads(records[0].read_text(encoding="utf-8"))
|
|
357
424
|
|
|
358
425
|
assert result.deleted == ("/tmp/a",)
|
|
359
|
-
assert payload["schema_version"] ==
|
|
426
|
+
assert payload["schema_version"] == 6
|
|
360
427
|
assert payload["deletion"]["strategy"] == "trash"
|
|
361
428
|
assert isinstance(payload["deletion"]["run_id"], str) and payload["deletion"]["run_id"]
|
|
362
429
|
assert payload["item"]["original_path"] == "/tmp/a"
|
|
363
430
|
assert payload["item"]["display_name"] == "A"
|
|
364
431
|
assert payload["item"]["size"] == 10
|
|
432
|
+
assert payload["status"] == "deleted"
|
|
365
433
|
|
|
366
434
|
|
|
367
435
|
def test_metadata_manager_records_archive_details(tmp_path: Path) -> None:
|
|
@@ -380,7 +448,7 @@ def test_metadata_manager_records_archive_details(tmp_path: Path) -> None:
|
|
|
380
448
|
records = sorted(storage_dir.glob("*.json"))
|
|
381
449
|
payload = json.loads(records[0].read_text(encoding="utf-8"))
|
|
382
450
|
|
|
383
|
-
assert payload["schema_version"] ==
|
|
451
|
+
assert payload["schema_version"] == 6
|
|
384
452
|
assert payload["archive"] == {"path": "/tmp/a.zip", "format": "zip", "compressed": True}
|
|
385
453
|
|
|
386
454
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Real-interruption tests for the compress-before-trash safety contract.
|
|
2
|
+
|
|
3
|
+
Every other test in ``test_deletion.py`` and ``test_compression.py`` simulates
|
|
4
|
+
a mid-operation failure by having ``monkeypatch`` make some step *raise*. That
|
|
5
|
+
is a good proxy for most failures (permission errors, ``OSError``, a
|
|
6
|
+
corrupt-archive detection), but it is not the same thing as a process getting
|
|
7
|
+
killed: a raised Python exception still runs any ``except``/``finally`` blocks
|
|
8
|
+
around it, while a crash, a SIGKILL, or the OOM killer stops execution dead at
|
|
9
|
+
whatever instruction it's on — no cleanup code downstream of that point ever
|
|
10
|
+
runs.
|
|
11
|
+
|
|
12
|
+
These tests use ``os.fork()`` + ``os._exit()`` (which, like a real kill,
|
|
13
|
+
skips exception handlers, ``finally`` blocks, and atexit hooks) to check the
|
|
14
|
+
same safety invariant under that harsher, more realistic form of
|
|
15
|
+
interruption: the source directory must never be touched until a verified
|
|
16
|
+
archive has already been confirmed safe in the trash.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import shutil
|
|
23
|
+
import tarfile
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
import pytest
|
|
27
|
+
|
|
28
|
+
from devklean.deletion import delete_items
|
|
29
|
+
from devklean.deletion.metadata import MetadataManager
|
|
30
|
+
from devklean.models import CleanableItem
|
|
31
|
+
|
|
32
|
+
pytestmark = pytest.mark.skipif(
|
|
33
|
+
not hasattr(os, "fork"), reason="os.fork is only available on POSIX platforms"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _make_source(tmp_path: Path) -> tuple[Path, int]:
|
|
38
|
+
source = tmp_path / "workspace" / "node_modules"
|
|
39
|
+
source.mkdir(parents=True)
|
|
40
|
+
(source / "a.txt").write_text("A" * 4096, encoding="utf-8")
|
|
41
|
+
(source / "b.txt").write_text("B" * 4096, encoding="utf-8")
|
|
42
|
+
size = sum(f.stat().st_size for f in source.rglob("*") if f.is_file())
|
|
43
|
+
return source, size
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _run_in_child(child_body) -> int:
|
|
47
|
+
"""Fork, run ``child_body`` in the child, and return its exit status.
|
|
48
|
+
|
|
49
|
+
``child_body`` must end the child process itself (typically by letting
|
|
50
|
+
the deliberately-triggered ``os._exit`` fire); as a safety net, a child
|
|
51
|
+
that returns normally without being "killed" exits with code 99 so a
|
|
52
|
+
broken test setup fails loudly instead of hanging or passing by
|
|
53
|
+
accident.
|
|
54
|
+
"""
|
|
55
|
+
pid = os.fork()
|
|
56
|
+
if pid == 0:
|
|
57
|
+
try:
|
|
58
|
+
child_body()
|
|
59
|
+
finally:
|
|
60
|
+
os._exit(99)
|
|
61
|
+
_, status = os.waitpid(pid, 0)
|
|
62
|
+
return status
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_kill_mid_archive_write_never_touches_source(tmp_path: Path) -> None:
|
|
66
|
+
"""A kill landing while the archive is still being built must leave the
|
|
67
|
+
source completely intact — the source is never read-and-deleted, only
|
|
68
|
+
ever read (for the archive) and left alone until much later.
|
|
69
|
+
"""
|
|
70
|
+
source, size = _make_source(tmp_path)
|
|
71
|
+
item = CleanableItem(str(source), "node_modules", size, "Node.js")
|
|
72
|
+
manager = MetadataManager(storage_dir=tmp_path / "m")
|
|
73
|
+
|
|
74
|
+
def _child() -> None:
|
|
75
|
+
# Kill the process at the first byte tarfile tries to write for the
|
|
76
|
+
# source tree -- i.e. the earliest possible moment inside the
|
|
77
|
+
# archive-build step, well before any verification or trashing.
|
|
78
|
+
def _killed(*_args, **_kwargs):
|
|
79
|
+
os._exit(37)
|
|
80
|
+
|
|
81
|
+
tarfile.TarFile.add = _killed
|
|
82
|
+
delete_items(
|
|
83
|
+
[item], item.size, metadata_manager=manager, compress=True, compress_min_size=0
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
status = _run_in_child(_child)
|
|
87
|
+
|
|
88
|
+
assert os.WIFEXITED(status)
|
|
89
|
+
assert os.WEXITSTATUS(status) == 37, "child never reached the archive-write step"
|
|
90
|
+
|
|
91
|
+
# The source is untouched: compress_path only ever reads it while
|
|
92
|
+
# building the archive, never deletes anything from it.
|
|
93
|
+
assert source.exists()
|
|
94
|
+
assert (source / "a.txt").read_text(encoding="utf-8") == "A" * 4096
|
|
95
|
+
assert (source / "b.txt").read_text(encoding="utf-8") == "B" * 4096
|
|
96
|
+
|
|
97
|
+
# A stray partial temp archive may be left behind -- a real kill skips
|
|
98
|
+
# the `except: archive_path.unlink()` cleanup in compress_path, unlike
|
|
99
|
+
# the monkeypatch-raise tests in test_compression.py. That's expected
|
|
100
|
+
# and harmless (it's disk litter, not data loss); nothing here asserts
|
|
101
|
+
# it's absent.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_kill_between_trash_confirmation_and_original_removal_loses_nothing(
|
|
105
|
+
tmp_path: Path,
|
|
106
|
+
) -> None:
|
|
107
|
+
"""A kill landing exactly when the original would start being removed --
|
|
108
|
+
i.e. *after* the archive has already been verified and confirmed safe in
|
|
109
|
+
the trash -- must never lose data overall. The live source directory may
|
|
110
|
+
end up partially removed (the kill can land mid-``rmtree``), but the
|
|
111
|
+
archive already sitting in the trash is a complete, verified copy, so
|
|
112
|
+
nothing is actually lost.
|
|
113
|
+
|
|
114
|
+
This is the exact ordering PR #12 got backwards: it ran ``rmtree(source)``
|
|
115
|
+
unconditionally right after building the archive, before ``send2trash``
|
|
116
|
+
even ran. Here ``send2trash`` has already succeeded by construction
|
|
117
|
+
before the kill fires, which is the fixed, safe order.
|
|
118
|
+
"""
|
|
119
|
+
source, size = _make_source(tmp_path)
|
|
120
|
+
item = CleanableItem(str(source), "node_modules", size, "Node.js")
|
|
121
|
+
manager = MetadataManager(storage_dir=tmp_path / "m")
|
|
122
|
+
|
|
123
|
+
trash_dir = tmp_path / "trash"
|
|
124
|
+
trash_dir.mkdir()
|
|
125
|
+
|
|
126
|
+
def _child() -> None:
|
|
127
|
+
import devklean.deletion.trash as trash_module
|
|
128
|
+
|
|
129
|
+
# A "real" trash: actually relocate the archive to trash_dir (rather
|
|
130
|
+
# than deleting it, like the fake_trash fixture does) so the parent
|
|
131
|
+
# process can inspect the surviving bytes after the kill and prove
|
|
132
|
+
# the data really is still there.
|
|
133
|
+
def _real_move_to_trash(path) -> None:
|
|
134
|
+
shutil.move(os.fspath(path), trash_dir / Path(path).name)
|
|
135
|
+
|
|
136
|
+
trash_module.send2trash = _real_move_to_trash
|
|
137
|
+
|
|
138
|
+
# Kill after one file has been removed from the source -- i.e. mid
|
|
139
|
+
# rmtree, having already deleted part of the original -- to prove a
|
|
140
|
+
# *partial* removal still isn't data loss, since the archive was
|
|
141
|
+
# already relocated to the trash before rmtree ever started.
|
|
142
|
+
def _killed_mid_rmtree(path, *_args, **_kwargs):
|
|
143
|
+
first_child = next(Path(path).iterdir())
|
|
144
|
+
first_child.unlink()
|
|
145
|
+
os._exit(37)
|
|
146
|
+
|
|
147
|
+
trash_module.shutil.rmtree = _killed_mid_rmtree
|
|
148
|
+
|
|
149
|
+
delete_items(
|
|
150
|
+
[item], item.size, metadata_manager=manager, compress=True, compress_min_size=0
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
status = _run_in_child(_child)
|
|
154
|
+
|
|
155
|
+
assert os.WIFEXITED(status)
|
|
156
|
+
assert os.WEXITSTATUS(status) == 37, "child never reached the original-removal step"
|
|
157
|
+
|
|
158
|
+
# The live source is now (as simulated) partially removed -- exactly one
|
|
159
|
+
# file gone, the rest still sitting there. That's an acceptable outcome,
|
|
160
|
+
# not the invariant under test.
|
|
161
|
+
remaining = sorted(p.name for p in source.iterdir())
|
|
162
|
+
assert len(remaining) == 1
|
|
163
|
+
|
|
164
|
+
# What actually matters: the archive made it to "trash" *before* the
|
|
165
|
+
# kill (send2trash returned, or _killed_mid_rmtree could never have
|
|
166
|
+
# run), and it is a complete, byte-correct copy -- so the union of
|
|
167
|
+
# {trashed archive} recovers everything, even though the live directory
|
|
168
|
+
# is now partial.
|
|
169
|
+
[archived] = list(trash_dir.glob("*.tar.gz"))
|
|
170
|
+
with tarfile.open(archived, mode="r:gz") as tar:
|
|
171
|
+
expected = {"a.txt": "A" * 4096, "b.txt": "B" * 4096}
|
|
172
|
+
contents: dict[str, str] = {}
|
|
173
|
+
for member in tar.getmembers():
|
|
174
|
+
if member.isreg():
|
|
175
|
+
extracted = tar.extractfile(member)
|
|
176
|
+
assert extracted is not None
|
|
177
|
+
contents[Path(member.name).name] = extracted.read().decode("utf-8")
|
|
178
|
+
assert contents == expected
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|