Skip to content

Commit 6b66cad

Browse files
committed
pdm merge_folders
1 parent 994b70e commit 6b66cad

File tree

2 files changed

+56
-73
lines changed

2 files changed

+56
-73
lines changed

pdm.lock

+51-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xklb/scripts/merge_folders.py

+5-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44

55
from xklb import usage
6-
from xklb.utils import arg_utils, devices, objects, printing
6+
from xklb.utils import arg_utils, devices, file_utils, objects, printing
77
from xklb.utils.log_utils import log
88

99

@@ -70,25 +70,6 @@ def gen_rename_data(destination_folder, destination_files, source_folder, source
7070
return source_rename_data
7171

7272

73-
def same_filesystem(path1, path2):
74-
stat1 = os.stat(path1)
75-
stat2 = os.stat(path2)
76-
return stat1.st_dev == stat2.st_dev
77-
78-
79-
def filter_valid_sources(args, destination_folder):
80-
valid_sources = []
81-
for source in args.sources:
82-
if same_filesystem(source, destination_folder):
83-
valid_sources.append(source)
84-
else:
85-
print(f"Skipping {source}. Source not on same filesystem as destination.")
86-
87-
if not valid_sources:
88-
print("No valid sources found. Sources and destination must be on the same filesystem.")
89-
raise SystemExit(1)
90-
91-
return valid_sources
9273

9374

9475
def get_clobber(args):
@@ -127,7 +108,10 @@ def mv(t):
127108
else:
128109
os.replace(t[1], t[2])
129110
else: ## file does not exist in destination already
130-
os.renames(t[1], t[2])
111+
try:
112+
os.renames(t[1], t[2])
113+
except Exception:
114+
file_utils.rename_move_file(t[1], t[2])
131115

132116
if args.simulate:
133117
for p in empty_folder_data:
@@ -162,7 +146,6 @@ def merge_folders() -> None:
162146
print("Destination:")
163147
destination_folder, destination_glob = args.destination
164148
destination_folder.mkdir(parents=True, exist_ok=True)
165-
args.sources = filter_valid_sources(args, destination_folder) # TODO: add cross-fs support
166149
destination_files, destination_folders_dict = existing_stats(destination_folder, destination_glob)
167150

168151
destination_folders = (

0 commit comments

Comments
 (0)