Hardware-Target-Game-Database icon indicating copy to clipboard operation
Hardware-Target-Game-Database copied to clipboard

File Deletion

Open Shentokk opened this issue 4 years ago • 6 comments

I'm able to do use the parse tool just fine, but when I run the build_pack.py script, it spits out an error and deletes a rom file. What's going on that's causing this? I'm using Python 3.8.5 in the Windows command line.

D:\Users\Shentok\Downloads\New folder>build_pack.py -i "D:\Users\Shentok\Downloads\New folder\GB" -d "D:\Users\Shentok\Downloads\New folder\GB.txt" -o "D:\Users\Shentok\Downloads\New folder\GBO"
Traceback (most recent call last):
  File "D:\Users\Shentok\Downloads\New folder\build_pack.py", line 136, in copy_file
    copy_fn(source, dest)
  File "C:\Users\Shentok\AppData\Local\Programs\Python\Python38-32\lib\shutil.py", line 261, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Users\\Shentok\\Downloads\\New folder\\GB\\4 in 1 (Europe) (4B-001, Sachen-Commin) (Unl).gb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Users\Shentok\Downloads\New folder\build_pack.py", line 311, in <module>
    parse_folder(SOURCE_FOLDER, DATABASE, OUTPUT_FOLDER)
  File "D:\Users\Shentok\Downloads\New folder\build_pack.py", line 239, in parse_folder
    copy_file(info['filename'], new_file, original)
  File "D:\Users\Shentok\Downloads\New folder\build_pack.py", line 140, in copy_file
    copy_fn(source, fixed_dest)
  File "C:\Users\Shentok\AppData\Local\Programs\Python\Python38-32\lib\shutil.py", line 261, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Users\\Shentok\\Downloads\\New folder\\GB\\4 in 1 (Europe) (4B-001, Sachen-Commin) (Unl).gb'

Shentokk avatar Oct 22 '20 00:10 Shentokk

@Shentokk I was not able to reproduce your issue yet. A test on Linux runs as expected:

python3 build_pack.py -i ./GBO/ -d GB_SMDB.txt -o ./GB/ -m missing.txt
processing file:      5147 / 5147
coverage: 10152/10517 (96.53%)

The problem does not seem to come from 4 in 1 (Europe) (4B-001, Sachen-Commin) (Unl).gb, as it is copied:

find ./GB*/ -name "*4B-001, Sachen-Commin*"
./GB/EverDrive GB/1 Game Boy/2 Unlicensed - A-Z/4 in 1 (Europe) (4B-001, Sachen-Commin) (Unl).gb
./GBO/1 Game Boy/2 Unlicensed - A-Z/4 in 1 (Europe) (4B-001, Sachen-Commin) (Unl).gb

This file occurs only once in the pack, so this is not an issue of "move-once fail to find it again". It could be a Windows-specific issue, or an issue with your ROM files. Is that file the first one in your source ROM folder?

frederic-mahe avatar Oct 22 '20 09:10 frederic-mahe

I ran build_pack.py on my Windows machine and not having any issues.

D:\tmp>build_pack.py -i GB_unparsed -d "EverDrive GB SMDB.txt" -o GB_parsed -m GB_missing.txt
processing file:      5147 / 5147
coverage: 10152/10517 (96.53%)

tjanas avatar Oct 22 '20 14:10 tjanas

Looks like it only happens when I parse my own packs as using the provided ones work fine. Also it doesn't only delete that rom, it deletes whatever rom is next on the list.

Shentokk avatar Oct 22 '20 18:10 Shentokk

Same problem happens for me (on Windows).

I found that problem only appears when i using absolute paths for arguments.

python parse_pack.py -f "e:\path\to\NES" -o "e:\path\to\NES\db.txt"
python build_pack.py -i "e:\path\to\NES" -d "e:\path\to\NES\db.txt" -o "e:\path\to\NESPACK" -m "e:\path\to\NESPACK\Missing.txt"

When scripts and all the folders in same place, then all works fine.

python parse_pack.py -f "NES" -o "NES\db.txt"
python build_pack.py -i "NES" -d "NES\db.txt" -o "NESPACK" -m "NESPACK\Missing.txt"

den1n avatar Oct 29 '20 06:10 den1n

Thanks @den1n that's very helpful.

I don't have a Windows machine with me at the moment, so I can't test that hypothesis. I think this is an issue that could be fixed by using os.path.normpath() on the target_folder and output_file variables of the main() function in parse_pack.py. Maybe like that:

if __name__ == '__main__':
    args = option_parse()
    TARGET_FOLDER = os.path.normpath(args.target_folder)
    OUTPUT_FILE = os.path.normpath(args.output_file)
    END_LINE = "\n" if args.new_line else "\r"
    if os.path.lexists(TARGET_FOLDER):
        parse_folder(TARGET_FOLDER, OUTPUT_FILE)

frederic-mahe avatar Dec 06 '20 14:12 frederic-mahe

I run my scripts on Windows with absolute file paths via batch files and I don't see this problem. @Shentokk You mention that the issue only happens on your packs and not the provided ones. I suspect it may have something to do with your custom SMDB. Would you be able to post your SMDB file?

steve1515 avatar Dec 06 '20 15:12 steve1515