Skip to content

Commit 6397968

Browse files
committed
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.
1 parent cb5c198 commit 6397968

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tzst/core.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,15 +762,21 @@ def extract_archive(
762762
interactive_callback: Function to call for interactive conflict resolution
763763
764764
Warning:
765-
Never extract archives from untrusted sources without proper filtering.
766-
The 'data' filter is recommended for most use cases as it prevents
765+
Never extract archives from untrusted sources without proper filtering. The 'data' filter is recommended for most use cases as it prevents
767766
dangerous security issues like path traversal attacks.
768767
769768
See Also:
770769
:meth:`TzstArchive.extract`: Method for extracting from an open archive
771770
"""
772771
with TzstArchive(archive_path, "r", streaming=streaming) as archive:
773-
state = ConflictResolutionState()
772+
# Convert string resolution to enum if needed
773+
if isinstance(conflict_resolution, str):
774+
try:
775+
conflict_resolution = ConflictResolution(conflict_resolution)
776+
except ValueError:
777+
conflict_resolution = ConflictResolution.REPLACE
778+
779+
state = ConflictResolutionState(conflict_resolution)
774780

775781
if flatten:
776782
# Extract files without directory structure

0 commit comments

Comments
 (0)