-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: use os.replace to handle existing .apkg files on Windows #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -124,16 +124,14 @@ def rename_temp_file(temp_path, sanitized_name, first_deck_id): | |||||||||||||||||||||||||||||||||||||||||||
| _verify_path_within_cwd(final_path, cwd) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| os.rename(temp_path, final_path) | ||||||||||||||||||||||||||||||||||||||||||||
| os.replace(temp_path, final_path) | ||||||||||||||||||||||||||||||||||||||||||||
| except OSError as e: | ||||||||||||||||||||||||||||||||||||||||||||
| if e.errno == 36: | ||||||||||||||||||||||||||||||||||||||||||||
| fallback_filename = f"deck_{uuid.uuid4().hex[:8]}.apkg" | ||||||||||||||||||||||||||||||||||||||||||||
| final_path = os.path.join(cwd, fallback_filename) | ||||||||||||||||||||||||||||||||||||||||||||
| _verify_path_within_cwd(final_path, cwd) | ||||||||||||||||||||||||||||||||||||||||||||
| os.rename(temp_path, final_path) | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"Warning: Filename too long. Saved as {final_path}") | ||||||||||||||||||||||||||||||||||||||||||||
| os.replace(temp_path, final_path) | ||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||
| print(f"Error renaming file: {e}") | ||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("Failed to rename file") from e | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
128
to
135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: fd -type f -name "write_apkg.py"Repository: 2anki/create_deck Length of output: 231 🏁 Script executed: find . -name "write_apkg.py" -type fRepository: 2anki/create_deck Length of output: 84 🏁 Script executed: cat -n ./helpers/write_apkg.py | head -150Repository: 2anki/create_deck Length of output: 5844 🏁 Script executed: python3 << 'EOF'
import errno
# Verify errno 36
print(f"errno 36 = {errno.errorcode.get(36, 'UNKNOWN')}")
EOFRepository: 2anki/create_deck Length of output: 84 Include paths and original error details in the At line 135, non- Proposed error-handling refinement try:
os.replace(temp_path, final_path)
except OSError as e:
if e.errno == 36:
fallback_filename = f"deck_{uuid.uuid4().hex[:8]}.apkg"
final_path = os.path.join(cwd, fallback_filename)
_verify_path_within_cwd(final_path, cwd)
os.replace(temp_path, final_path)
else:
- raise ValueError("Failed to rename file") from e
+ raise ValueError(
+ f"Failed to rename temp file '{temp_path}' to '{final_path}': {e}"
+ ) from e📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: Test[error] 127-135: File rename in rename_temp_file failed: FileNotFoundError when executing os.replace(temp_path, final_path), temp file does not exist. Exception is caught and re-raised as ValueError("Failed to rename file"). 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return final_path | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.