Skip to content

Commit 32cd0ec

Browse files
committed
fix: use shutil.copy instead of copy2 to avoid SMB permission errors
shutil.copy2 calls copystat() which reads metadata (xattrs, ownership) from the source. On SMB shares on macOS and Linux this raises [Errno 1] Operation not permitted even with full read access, causing the copy to be counted as an error and the WhatsApp timestamp to not be applied. Switch to shutil.copy (data only) and rely on set_file_times() for the timestamp — which is what we want anyway. Isolate the utime call in its own try/except so a failure on the destination side is logged at DEBUG without affecting the copy count.
1 parent ebc1231 commit 32cd0ec

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎wa_media_archiver.py‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,18 +619,21 @@ def _copy_or_skip(src, dest_path, dest_dir, file_path, timestamp,
619619

620620
os.makedirs(dest_dir, exist_ok=True)
621621
try:
622-
shutil.copy2(src, resolved)
623-
set_file_times(resolved, timestamp)
624-
if src_hash is None:
625-
src_hash = file_md5(resolved)
626-
logger.debug(f"COPIED: {src} -> {resolved}")
627-
if cursor is not None:
628-
rel = os.path.relpath(resolved, output_root).replace(os.sep, '/')
629-
record_file_archived(cursor, file_path, src_hash, rel)
630-
return 1, 0, 0
622+
shutil.copy(src, resolved)
631623
except Exception as e:
632624
logger.error(f"ERROR copying {src} -> {resolved}: {e}")
633625
return 0, 0, 1
626+
try:
627+
set_file_times(resolved, timestamp)
628+
except OSError as e:
629+
logger.debug(f"Could not set timestamps on {resolved}: {e}")
630+
if src_hash is None:
631+
src_hash = file_md5(resolved)
632+
logger.debug(f"COPIED: {src} -> {resolved}")
633+
if cursor is not None:
634+
rel = os.path.relpath(resolved, output_root).replace(os.sep, '/')
635+
record_file_archived(cursor, file_path, src_hash, rel)
636+
return 1, 0, 0
634637

635638

636639
def process_rows(rows, total: int, contacts, number_map, folder_index, group_index,

0 commit comments

Comments
 (0)