Skip to content

Commit 2500efb

Browse files
author
Iago Veloso
committed
Avoid corrupting catalogue db when dry-run
1 parent 7057d5d commit 2500efb

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ The easier way to run this project is using docker:
4949
5050
Run example; notice `source` and `my_catalogue` need to be replace with your destinations:
5151
52-
docker run --rm -v $(pwd)/source:/input:ro -v $(pwd)/my_catalogue:/output iago1460/catalogue:1.2.2 --src /input --dst /output --operation copy
52+
docker run --rm -v $(pwd)/source:/input:ro -v $(pwd)/my_catalogue:/output iago1460/catalogue:1.2.3 --src /input --dst /output --operation copy
5353
5454
5555
### In a virtual environment
5656
5757
virtualenv venv
5858
source venv/bin/activate
59-
pip3 install https://github.com/iago1460/photo-cataloguer/archive/1.2.2.zip
59+
pip3 install https://github.com/iago1460/photo-cataloguer/archive/1.2.3.zip
6060
catalogue --help
6161
6262

catalogue/main.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ def main():
203203
file, args.operation, dst_catalogue, dst_file_path
204204
)
205205
imported_files.append(processed_file)
206-
logging.info("Saving catalogue...")
207-
dst_catalogue.save_db()
206+
207+
if args.operation != Operation.DRY_RUN: # shouldn't save if dry run (data is messed up too)
208+
logging.info("Saving catalogue...")
209+
dst_catalogue.save_db()
208210

209211
logging.info("Report:")
210212
logging.info(f"{len(imported_files)} files imported.")
@@ -231,20 +233,17 @@ def process_file(file, operation, dst_catalogue, dst_file_path):
231233
dst_file_path = dst_catalogue.find_new_path(dst_file_path)
232234

233235
if operation == Operation.DRY_RUN:
236+
print(f"dry-run: {file.path} -> {dst_file_path}")
234237
file.path = dst_file_path
235-
dst_catalogue.add_file(file)
236-
if path_available:
237-
logging.info(f"dry-run: {file.path} -> {dst_file_path}")
238-
else:
239-
logging.warning(f"dry-run: {file.path} -> {dst_file_path}")
238+
dst_catalogue.add_file(file) # needed so path_available is more accurate
240239
return None
241240

242241
if operation == Operation.COPY:
243242
new_file = file.clone_file(dst_file_path)
244243
dst_catalogue.add_file(new_file)
245244
return new_file
246245
elif operation == Operation.MOVE:
247-
file.move_file(dst_catalogue)
246+
file.move_file(dst_file_path)
248247
dst_catalogue.add_file(file)
249248
return file
250249

0 commit comments

Comments
 (0)