Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bleach==6.1.0
requests==2.31.0
Werkzeug==3.0.1
resend==2.0.0
rustyzipper==1.0.6

# Testing
pytest==7.4.3
Expand Down
45 changes: 8 additions & 37 deletions review/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import bcrypt
import requests
from subprocess import call
from rustyzipper import compress_file, EncryptionMethod
from bson.objectid import ObjectId

from review.logger import log_reviewer_operation
Expand Down Expand Up @@ -498,56 +498,27 @@ def create_password_protected_zip(source_path, dest_path_without_ext, filename_i
Returns:
Tuple of (success: bool, error_message: str or None)
"""
# Move to temp location with desired filename
dest_path = dest_path_without_ext + '.zip'
temp_path = os.path.join(CRACKMESONE_DIR, filename_in_archive)
shutil.move(source_path, temp_path)

try:
# Find zip command (use full path to avoid PATH issues in web server)
zip_cmd = shutil.which("zip") or "/usr/bin/zip"

# Create password-protected zip
ret = call([
zip_cmd, "-j", "--password", ARCHIVE_PASSWORD,
dest_path_without_ext, "--", temp_path
])

if ret != 0:
# Move file back on failure
if os.path.exists(temp_path):
try:
shutil.move(temp_path, source_path)
except Exception:
pass
return False, "Failed to create zip archive"

shutil.move(source_path, temp_path)
compress_file(temp_path, dest_path, password=ARCHIVE_PASSWORD, encryption=EncryptionMethod.ZIPCRYPTO, suppress_warning=True)
os.remove(temp_path)
return True, None

except FileNotFoundError:
# zip command not found - move file back
if os.path.exists(temp_path):
try:
shutil.move(temp_path, source_path)
except Exception:
pass
return False, "zip command not found"

except Exception as e:
# Other errors - move file back
if os.path.exists(temp_path):
try:
shutil.move(temp_path, source_path)
except Exception:
pass
return False, f"Error creating zip: {str(e)}"

finally:
# Clean up temp file (only if zip succeeded, file was moved to archive)
if os.path.exists(temp_path):
if os.path.exists(dest_path):
try:
os.remove(temp_path)
os.remove(dest_path)
except Exception:
pass
return False, f"Error creating zip: {str(e)}"


# =============================================================================
Expand Down