@@ -770,12 +770,13 @@ func NewDirContext() DirContext {
770770
771771// Move implements FileSystemOperation to move files from source to destination.
772772type Move struct {
773- dryRun bool
773+ dryRun bool
774+ destMode os.FileMode
774775}
775776
776777// NewMove creates a new Move operation with the specified dry-run mode.
777778// If dryRun is true, no files will actually be moved.
778- func NewMove (dryRun bool ) Move { return Move {dryRun : dryRun } }
779+ func NewMove (dryRun bool , destMode os. FileMode ) Move { return Move {dryRun : dryRun , destMode : destMode } }
779780
780781// CanModifyDest returns whether this operation can modify destination files.
781782// For Move operations, this is determined by the dryRun setting.
@@ -811,10 +812,14 @@ func (m Move) ProcessPath(ctx context.Context, dc DirContext, src, dest string)
811812 if err := os .Remove (src ); err != nil {
812813 return fmt .Errorf ("remove from move: %w" , err )
813814 }
815+ if err := os .Chmod (dest , m .destMode ); err != nil {
816+ return fmt .Errorf ("chmod dest: %w" , err )
817+ }
814818
815819 slog .DebugContext (ctx , "moved path" , "from" , src , "to" , dest )
816820 return nil
817821 }
822+
818823 return fmt .Errorf ("rename: %w" , err )
819824 }
820825
@@ -853,12 +858,13 @@ func (m Move) PostSource(ctx context.Context, dc DirContext, limit string, src s
853858
854859// Copy implements FileSystemOperation to copy files from source to destination.
855860type Copy struct {
856- dryRun bool
861+ dryRun bool
862+ destMode os.FileMode
857863}
858864
859865// NewCopy creates a new Copy operation with the specified dry-run mode.
860866// If dryRun is true, no files will actually be copied.
861- func NewCopy (dryRun bool ) Copy { return Copy {dryRun : dryRun } }
867+ func NewCopy (dryRun bool , destMode os. FileMode ) Copy { return Copy {dryRun : dryRun , destMode : destMode } }
862868
863869// CanModifyDest returns whether this operation can modify destination files.
864870// For Copy operations, this is determined by the dryRun setting.
@@ -889,6 +895,10 @@ func (c Copy) ProcessPath(ctx context.Context, dc DirContext, src, dest string)
889895 return err
890896 }
891897
898+ if err := os .Chmod (dest , c .destMode ); err != nil {
899+ return fmt .Errorf ("chmod dest: %w" , err )
900+ }
901+
892902 slog .DebugContext (ctx , "copied path" , "from" , src , "to" , dest )
893903 return nil
894904}
@@ -901,12 +911,15 @@ func (Copy) PostSource(ctx context.Context, dc DirContext, limit string, src str
901911
902912// Reflink implements FileSystemOperation to copy files using reflink (copy-on-write) when supported.
903913type Reflink struct {
904- dryRun bool
914+ dryRun bool
915+ destMode os.FileMode
905916}
906917
907918// NewReflink creates a new Reflink operation with the specified dry-run mode.
908919// If dryRun is true, no files will actually be reflinked.
909- func NewReflink (dryRun bool ) Reflink { return Reflink {dryRun : dryRun } }
920+ func NewReflink (dryRun bool , destMode os.FileMode ) Reflink {
921+ return Reflink {dryRun : dryRun , destMode : destMode }
922+ }
910923
911924// CanModifyDest returns whether this operation can modify destination files.
912925// For Reflink operations, this is determined by the dryRun setting.
@@ -937,6 +950,10 @@ func (c Reflink) ProcessPath(ctx context.Context, dc DirContext, src, dest strin
937950 return fmt .Errorf ("reflink file: %w" , err )
938951 }
939952
953+ if err := os .Chmod (dest , c .destMode ); err != nil {
954+ return fmt .Errorf ("chmod dest: %w" , err )
955+ }
956+
940957 slog .DebugContext (ctx , "reflinked path" , "from" , src , "to" , dest )
941958 return nil
942959}
0 commit comments