@@ -1452,15 +1452,22 @@ def copy(
1452
1452
dest_dir = Path (dest_dir )
1453
1453
# Logic to determine the laziest mode to use
1454
1454
mode = self .CopyMode [mode ] if isinstance (mode , str ) else mode
1455
+ logger .debug ("Requested '%s' for the copy operation" , mode )
1455
1456
if len (self .fspaths ) == 1 :
1456
1457
# If there is only one path to copy, then collation isn't meaningful
1457
1458
collation = self .CopyCollation .any
1459
+ logger .debug (
1460
+ "Collation mode is set to 'any' as there is only one path in the fileset"
1461
+ )
1458
1462
else :
1459
1463
collation = (
1460
1464
self .CopyCollation [collation ]
1461
1465
if isinstance (collation , str )
1462
1466
else collation
1463
1467
)
1468
+ logger .debug (
1469
+ "Collation mode is set to '%s' for the copy operation" , collation
1470
+ )
1464
1471
# Rule out any copy modes that are not supported given the collation mode
1465
1472
# and file-system mounts the paths and destination directory reside on
1466
1473
constraints = []
@@ -1473,7 +1480,9 @@ def copy(
1473
1480
f"Destination directory is on CIFS mount ({ dest_dir } ) "
1474
1481
"and we therefore cannot create a symlink"
1475
1482
)
1476
- logger .debug (constraint )
1483
+ logger .debug (
1484
+ constraint + ", supported modes restricted to %s" , supported_modes
1485
+ )
1477
1486
constraints .append (constraint )
1478
1487
not_on_same_mount = [
1479
1488
p for p in self .fspaths if not FsMountIdentifier .on_same_mount (p , dest_dir )
@@ -1485,7 +1494,9 @@ def copy(
1485
1494
f"not on same file-system mount as the destination directory { dest_dir } "
1486
1495
"and therefore cannot be hard-linked"
1487
1496
)
1488
- logger .debug (constraint )
1497
+ logger .debug (
1498
+ constraint + ", supported modes restricted to %s" , supported_modes
1499
+ )
1489
1500
constraints .append (constraint )
1490
1501
if (
1491
1502
new_stem
@@ -1497,9 +1508,19 @@ def copy(
1497
1508
)
1498
1509
):
1499
1510
supported_modes -= self .CopyMode .leave
1511
+ logger .debug (
1512
+ "Collation mode is set to '%s' or new_stem/prefix/stem_suffix is set, "
1513
+ "therefore we cannot leave the files where they are" ,
1514
+ collation ,
1515
+ )
1500
1516
1501
1517
# Get the intersection of copy modes that are supported and have been requested
1502
1518
selected_mode = mode & supported_modes
1519
+ logger .debug (
1520
+ "Selected copy mode is '%s' for the copy operation (requested %s)" ,
1521
+ selected_mode ,
1522
+ mode ,
1523
+ )
1503
1524
if not selected_mode :
1504
1525
msg = (
1505
1526
f"Cannot copy { self } using '{ mode } ' mode as it is not supported by "
@@ -1509,15 +1530,20 @@ def copy(
1509
1530
msg += ", and the following constraints:\n " + "\n " .join (constraints )
1510
1531
raise UnsatisfiableCopyModeError (msg )
1511
1532
if selected_mode & self .CopyMode .leave :
1533
+ logger .debug (
1534
+ "Selected copy mode is set to 'leave', therefore we are not copying anything"
1535
+ )
1512
1536
return self # Don't need to do anything
1513
1537
1514
1538
copy_file : ty .Callable [[Path , Path ], None ]
1515
1539
copy_dir : ty .Callable [[Path , Path ], None ]
1516
1540
1517
1541
# Select inner copy/link methods
1518
1542
if selected_mode & self .CopyMode .symlink :
1543
+ logger .debug ('Using symbolic links for the "copy" operation' )
1519
1544
copy_dir = copy_file = os .symlink
1520
1545
elif selected_mode & self .CopyMode .hardlink :
1546
+ logger .debug ('Using hard links for the "copy" operation' )
1521
1547
copy_file = os .link
1522
1548
1523
1549
def hardlink_dir (src : Path , dest : Path ) -> None :
@@ -1530,6 +1556,7 @@ def hardlink_dir(src: Path, dest: Path) -> None:
1530
1556
1531
1557
copy_dir = hardlink_dir
1532
1558
else :
1559
+ logger .debug ('Using full copy for the "copy" operation' )
1533
1560
assert selected_mode & self .CopyMode .copy
1534
1561
copy_dir = shutil .copytree
1535
1562
copy_file = shutil .copyfile # type: ignore
@@ -1737,10 +1764,15 @@ def _src_dest_pairs(
1737
1764
exts = [d [- 1 ] for d in decomposed_fspaths ]
1738
1765
duplicate_exts = [n for n , c in Counter (exts ).items () if c > 1 ]
1739
1766
if duplicate_exts :
1767
+ reason = ""
1768
+ if new_stem :
1769
+ reason += f"with a new stem, { new_stem !r} , "
1770
+ if collation == self .CopyCollation .adjacent :
1771
+ reason += f"with collation mode '{ collation } ', "
1740
1772
raise UnsatisfiableCopyModeError (
1741
- f"Cannot copy/move { self } with collation mode "
1742
- f'" { collation } ", as there are duplicate extensions, { duplicate_exts } , '
1743
- f"in file paths: " + "\n " .join (str (p ) for p in self .fspaths )
1773
+ f"Cannot copy/move { self } { reason } as there are duplicate "
1774
+ f" extensions, { duplicate_exts } , in file paths: "
1775
+ + "\n " .join (str (p ) for p in self .fspaths )
1744
1776
)
1745
1777
# Set default for new_stem if not provided and collating file-set to be adjacent
1746
1778
if new_stem is None :
0 commit comments