Skip to content

Commit 172fee8

Browse files
committed
fix(cp): use target file mode for symlinks when following links
When copying directories with followLinks=true, symlinks show 0777 mode but that's not the target file's actual permissions. Now we pass mode=0 for followed symlinks so CpToInstance auto-detects from the target via os.Stat.
1 parent 40c729e commit 172fee8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/cp.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,23 @@ func copyDirToWs(ctx context.Context, cfg CpConfig, ws WsConn, srcPath, dstPath,
348348
return fmt.Errorf("info: %w", err)
349349
}
350350

351+
// Determine the mode to use
352+
// For symlinks: if following links, let CpToInstance auto-detect from target
353+
// (symlinks show 0777 but that's not the target's actual mode)
354+
var mode fs.FileMode
355+
if info.Mode()&fs.ModeSymlink != 0 && followLinks {
356+
mode = 0 // Let CpToInstance use os.Stat to get target's mode
357+
} else {
358+
mode = info.Mode().Perm()
359+
}
360+
351361
// For each file/dir, we need a new WebSocket connection
352362
// This is because the protocol is one-file-per-connection
353363
return CpToInstance(ctx, cfg, CpToInstanceOptions{
354364
InstanceID: instanceID,
355365
SrcPath: walkPath,
356366
DstPath: targetPath,
357-
Mode: info.Mode().Perm(),
367+
Mode: mode,
358368
Archive: archive,
359369
FollowLinks: followLinks,
360370
Dialer: dialer,

0 commit comments

Comments
 (0)