Improve conflict resolution in archive extraction

Updated the `extract_archive` function to handle string-based conflict resolution by converting it to an enum. Added fallback to `ConflictResolution.REPLACE` for invalid values, ensuring safer and more predictable behavior.
This commit is contained in:
xixu-me committed 2025-06-04 19:27:41 +08:00
1 parent cb5c198d16
commit 6397968a4d
1 file changed
+9 -3
+9 -3
View File
@@ -762,15 +762,21 @@ def extract_archive(
interactive_callback: Function to call for interactive conflict resolution
Warning:
Never extract archives from untrusted sources without proper filtering.
The 'data' filter is recommended for most use cases as it prevents
Never extract archives from untrusted sources without proper filtering. The 'data' filter is recommended for most use cases as it prevents
dangerous security issues like path traversal attacks.
See Also:
:meth:`TzstArchive.extract`: Method for extracting from an open archive
"""
with TzstArchive(archive_path, "r", streaming=streaming) as archive:
state = ConflictResolutionState()
# Convert string resolution to enum if needed
if isinstance(conflict_resolution, str):
try:
conflict_resolution = ConflictResolution(conflict_resolution)
except ValueError:
conflict_resolution = ConflictResolution.REPLACE
state = ConflictResolutionState(conflict_resolution)
if flatten:
# Extract files without directory structure