Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roachprod: fix symlink detection #111136

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/roachprod/install/cluster_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -1734,15 +1734,24 @@ func (c *SyncedCluster) Put(
if potentialSymlinkPath, err = filepath.EvalSymlinks(src); err != nil {
return err
}

absSrc, err := filepath.Abs(src)
if err != nil {
return fmt.Errorf("error computing absolute path for %s: %w", src, err)
}
absSymlink, err := filepath.Abs(potentialSymlinkPath)
if err != nil {
return fmt.Errorf("error computing absolute path for %s: %w", potentialSymlinkPath, err)
}
// Different paths imply it is a symlink.
if potentialSymlinkPath != src {
if absSrc != absSymlink {
// Get target symlink access mode.
var symlinkTargetInfo fs.FileInfo
if symlinkTargetInfo, err = os.Stat(potentialSymlinkPath); err != nil {
return err
}
redColor, resetColor := "\033[31m", "\033[0m"
l.Printf(redColor + "WARNING: Source file is a symlink." + resetColor)
l.Printf(redColor+"WARNING: Source file is a symlink to %s"+resetColor, absSymlink)
l.Printf(redColor+"WARNING: Remote file will inherit the target permissions '%v'."+resetColor, symlinkTargetInfo.Mode())
}

Expand Down