@@ -676,8 +676,16 @@ def _rename(self, old_filename, metadata, settings):
676676 new_dirname = os .path .dirname (new_filename )
677677 if not os .path .isdir (new_dirname ):
678678 os .makedirs (new_dirname )
679- if not settings ['move_overwrite_existing_files' ]:
680- new_filename = get_available_filename (new_filename , old_filename )
679+ config = get_config ()
680+ strategy = config .setting .get ('move_conflict_strategy' , 'rename' )
681+ if os .path .exists (new_filename ):
682+ if strategy == "skip" :
683+ log .warning ("Destination exists, skipping move of %r" , old_filename )
684+ return old_filename
685+ elif strategy == "rename" :
686+ new_filename = get_available_filename (new_filename , old_filename )
687+ elif strategy == "overwrite" :
688+ pass
681689 log .debug ("Moving file %r => %r" , old_filename , new_filename )
682690 move_ensure_casing (old_filename , new_filename )
683691 return new_filename
@@ -697,7 +705,6 @@ def _save_images(self, dirname, metadata):
697705 images = metadata .images
698706 for image in images :
699707 image .save (dirname , metadata , counters )
700-
701708 def _move_additional_files (self , old_filename , new_filename , config ):
702709 """Move extra files, like images, playlists…"""
703710 if config .setting ['move_files' ] and config .setting ['move_additional_files' ]:
@@ -708,7 +715,7 @@ def _move_additional_files(self, old_filename, new_filename, config):
708715 patterns = self ._compile_move_additional_files_pattern (patterns_string )
709716 try :
710717 moves = self ._get_additional_files_moves (old_path , new_path , patterns )
711- self ._apply_additional_files_moves (moves , config . setting [ 'move_overwrite_existing_files' ] )
718+ self ._apply_additional_files_moves (moves )
712719 except OSError as why :
713720 log .error ("Failed to scan %r: %s" , old_path , why )
714721
@@ -732,15 +739,22 @@ def _get_additional_files_moves(self, old_path, new_path, patterns):
732739 yield (entry .path , new_file_path )
733740 break # we are done with this file
734741
735- def _apply_additional_files_moves (self , moves , overwrite_existing_files = False ):
742+ def _apply_additional_files_moves (self , moves ):
743+ config = get_config ()
744+ strategy = config .setting .get ('move_conflict_strategy' , 'rename' )
736745 for old_file_path , new_file_path in moves :
737746 # FIXME we shouldn't do this from a thread!
738747 if self .tagger .files .get (decode_filename (old_file_path )):
739748 log .debug ("File loaded in the tagger, not moving %r" , old_file_path )
740749 continue
741- if not overwrite_existing_files and os .path .exists (new_file_path ):
742- log .warning ("File %r already exists, not moving %r" , new_file_path , old_file_path )
743- continue
750+ if os .path .exists (new_file_path ):
751+ if strategy == "skip" :
752+ log .warning ("File %r exists, skipping %r" , new_file_path , old_file_path )
753+ continue
754+ elif strategy == "rename" :
755+ new_file_path = get_available_filename (new_file_path )
756+ elif strategy == "overwrite" :
757+ pass
744758 log .debug ("Moving %r to %r" , old_file_path , new_file_path )
745759 try :
746760 shutil .move (old_file_path , new_file_path )
0 commit comments