@@ -704,28 +704,34 @@ sub saveFileChanges ($c, $outputFilePath, $backup = 0) {
704704 }
705705
706706 # If the file is being saved as a new file in a new location, and the file is accompanied by auxiliary files
707- # transfer them as well. If the file is a pg file, then assume there are auxiliary files. Copy all files not
708- # ending in .pg from the original directory to the new one.
709- if ($c -> {action } eq ' save_as' && $outputFilePath =~ / \. pg/ ) {
707+ # transfer them as well. If the option 'copyAuxFiles' is set and the file is a pg file, then assume there are
708+ # auxiliary files. Copy all files not ending in .pg from the original directory to the new one.
709+ if ($c -> {action } eq ' save_as' && $c -> param( ' copyAuxFiles ' ) && $ outputFilePath =~ / \. pg/ ) {
710710 my $sourceDirectory = Mojo::File-> new(($c -> {sourceFilePath } || ' ' ) =~ s | /[^/]+\. pg$|| r );
711711 my $outputDirectory = Mojo::File-> new($outputFilePath =~ s | /[^/]+\. pg$|| r );
712712
713713 # Only perform the copy if the output directory is an actual new location.
714714 if ($sourceDirectory ne $outputDirectory && -d $sourceDirectory ) {
715+ my $filesCopied = 0;
715716 for my $file (@{ $sourceDirectory -> list }) {
716717 # The .pg file being edited has already been transferred. Ignore any others in the directory.
717718 next if $file =~ / \. pg$ / ;
718719 my $toPath = $outputDirectory -> child($file -> basename);
719720 # Only copy regular files that are readable and that have not already been copied.
720721 if (-f $file && -r $file && !-e $toPath ) {
721722 eval { $file -> copy_to($toPath ) };
722- $c -> addbadmessage($c -> maketext(' Error copying [_1] to [_2].' , $file , $toPath )) if $@ ;
723+ if ($@ ) {
724+ $c -> addbadmessage($c -> maketext(' Error copying [_1] to [_2].' , $file , $toPath ));
725+ } else {
726+ $filesCopied = 1;
727+ }
723728 }
724729 }
725730 $c -> addgoodmessage($c -> maketext(
726731 ' Copied auxiliary files from [_1] to new location at [_2].' ,
727732 $sourceDirectory , $outputDirectory
728- ));
733+ ))
734+ if $filesCopied ;
729735 }
730736 }
731737
0 commit comments