Skip to content

Commit

Permalink
2.8.062
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Jun 13, 2024
1 parent d50b066 commit 750026b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
<details><summary>List all subcommands</summary>

$ library
library (v2.8.061; 79 subcommands)
library (v2.8.062; 79 subcommands)

Create database subcommands:
╭───────────────┬──────────────────────────────────────────╮
Expand Down
4 changes: 4 additions & 0 deletions tests/folders/test_merge_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def test_merge(mode, src_type, dest_type, temp_file_tree):
assert target_inodes == dest_inodes
elif src_type == "file" and dest_type == "clobber_file":
assert target_inodes == {"file4.txt": (0, "5")}
elif dest_type == "clobber_file" and mode == "--file-over-file skip":
assert target_inodes == src1_inodes | {"file4.txt": (0, "4")}
elif dest_type == "clobber_file" and mode == '--file-over-file "delete-dest-hash rename-src"':
assert target_inodes == src1_inodes | {"file4.txt": (0, "4"), "file4_1.txt": (0, "5")}
elif dest_type == "clobber_file":
assert target_inodes == src1_inodes | {"file4.txt": (0, "5")}

Expand Down
2 changes: 1 addition & 1 deletion xklb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.8.061"
__version__ = "2.8.062"
23 changes: 16 additions & 7 deletions xklb/utils/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,26 @@ def rename(args, src, dst):
if args.simulate:
print("rename", src, dst)
else:
log.debug("rename\t%s\t%s", src, dst)
os.rename(src, dst)


def unlink(args, p):
if args.simulate:
print("unlink", p)
else:
log.debug("unlink\t%s", p)
os.unlink(p)


def rmtree(args, p):
if args.simulate:
print("rmtree", p)
elif os.path.isdir(p):
log.debug("rmtree\t%s", p)
shutil.rmtree(p)
else:
log.debug("unlink\t%s", p)
os.unlink(p)


Expand Down Expand Up @@ -184,7 +188,7 @@ def clobber(args, source, destination) -> tuple[str | None, str]:
destination = file_utils.alt_name(destination)
case arggroups.FileOverFile.RENAME_DEST:
existing_rename = file_utils.alt_name(destination)
os.rename(destination, existing_rename)
rename(args, destination, existing_rename)
case arggroups.FileOverFile.DELETE_SRC:
unlink(args, source)
source = None
Expand Down Expand Up @@ -212,14 +216,19 @@ def clobber(args, source, destination) -> tuple[str | None, str]:
source = None
case arggroups.FolderOverFile.DELETE_DEST:
unlink(args, parent_file)
case arggroups.FolderOverFile.RENAME_DEST | arggroups.FolderOverFile.MERGE:
case arggroups.FolderOverFile.RENAME_DEST:
existing_rename = file_utils.alt_name(parent_file)
rename(args, parent_file, existing_rename)
if args.folder_over_file == arggroups.FolderOverFile.MERGE:
os.makedirs(parent_dir, exist_ok=True) # there can't be more than one blocking file
while os.path.exists(parent_file): # until we find an open file slot
parent_file = os.path.join(parent_file, os.path.basename(parent_file)) # down
rename(args, existing_rename, parent_file) # temporary rename to final dest
case arggroups.FolderOverFile.MERGE:
temp_rename = file_utils.alt_name(parent_file)
rename(args, parent_file, temp_rename)
os.makedirs(parent_dir, exist_ok=True) # there can't be more than one blocking file

while os.path.exists(parent_file): # until we find an open file slot
parent_file = os.path.join(parent_file, os.path.basename(parent_file)) # down
rename(args, temp_rename, parent_file) # temporary rename to final dest
if destination == parent_file:
return clobber(args, source, destination)

if source:
os.makedirs(parent_dir, exist_ok=True) # original destination parent
Expand Down

0 comments on commit 750026b

Please sign in to comment.