chore(script): add safety check for identical files during unification and move files#2579
chore(script): add safety check for identical files during unification and move files#2579DevGeniusCode wants to merge 2 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| scripts/cpp/unify_move_files.py | Adds existence + identity safety checks to unify_file; the previously reported FileNotFoundError from filecmp.cmp is fixed. One minor diagnostic gap: the error message on line 87 doesn't specify which of the two paths is missing. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["unify_file(fromGame, fromFile, toGame, toFile)"] --> B{fromFile exists in\nfromGame dir?}
B -- No --> C["print ERROR: file missing\nreturn (skip)"]
B -- Yes --> D{fromFile exists in\noppositeGame dir?}
D -- No --> C
D -- Yes --> E{filecmp.cmp\nbyte-for-byte match?}
E -- No --> F["print ERROR: files differ\nreturn (skip)"]
E -- Yes --> G[Modify CMakeLists:\ncomment out in both games]
G --> H[Uncomment in Core CMakeLists]
H --> I[delete_file from oppositeGame]
I --> J[move_file from fromGame to Core]
Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/cpp/unify_move_files.py
Line: 86-88
Comment:
**Ambiguous "missing file" error message**
The message says "One or both files do not exist!" but doesn't reveal *which* path is absent, making it harder to diagnose the root cause (e.g. was it already moved, does it have a different relative path in the other game's directory, etc.). Printing the missing path directly would make the output immediately actionable.
```suggestion
if not os.path.exists(fullFromPath):
print(f"ERROR: Source file does not exist! Skipping: {fullFromPath}")
return
if not os.path.exists(fullOppositePath):
print(f"ERROR: Opposite-game file does not exist! Skipping: {fullOppositePath}")
return
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "Fix FileNotFoundError" | Re-trigger Greptile
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
|
||
| import os | ||
| import shutil | ||
| import filecmp |
|
|
||
| if not os.path.exists(fullFromPath) or not os.path.exists(fullOppositePath): | ||
| print(f"ERROR: One or both files do not exist! Skipping: {fromFile}") | ||
| return |
There was a problem hiding this comment.
Previously it errored when a file was not found, stopping the entire script. This was intentional, to make very clear that there is an invocation error that needs addressing before continuing.
I suspect this test was added to so that it is possible to rerun the script without resetting the invocation setup?
This should then also be done in the other unify functions.
Better make this a separate helper function similar to move_file
| print(f"ERROR: One or both files do not exist! Skipping: {fromFile}") | ||
| return | ||
|
|
||
| if not filecmp.cmp(fullFromPath, fullOppositePath, shallow=False): |
There was a problem hiding this comment.
Better make this a separate helper function similar to move_file
| print(f"ERROR: One or both files do not exist! Skipping: {fromFile}") | ||
| return | ||
|
|
||
| if not filecmp.cmp(fullFromPath, fullOppositePath, shallow=False): |
There was a problem hiding this comment.
Does this really work correctly? Typically the first lines are different between Generals and Zero Hour source files, because of the Copyright header (intentional).
There was a problem hiding this comment.
I think the difference lies in how we merge the files. I first compare the files using the diff window and adjust any mismatches (including the first few lines) so that the Vanilla and MD files are completely identical. Only then do I transfer them
There was a problem hiding this comment.
Merging the Copyright header in the first line is incorrect (!)
Generals must keep its Generals header, otherwise git will have difficulties resolving the rename and will pick Generals or Zero Hour at random, but we want git to always assume that Generals file is deleted and Zero Hour is moved to Core. Reason: This makes merging conflicts easier, because all our WIP changes touch Zero Hour first.
There was a problem hiding this comment.
Got it, that makes perfect sense. I was trying to manually resolve all differences (comments, whitespace, etc.) to make the files identical before moving them, but I see how this interferes with Git's tracking. Moving forward, I’ll make sure the Core files remain exact copies of the Zero Hour version to preserve the history. Thanks!
Updated the file unification script to include a safety mechanism that prevents accidental data loss during the move/merge process.
The script now skips files and prints an error message if a mismatch is detected, allowing for manual inspection.