Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
fix: update ownership of user homedir
  • Loading branch information
johnstcn committed Jun 14, 2024
commit dbfeedb5c0eff39afdcda05f64769f9650048d76
27 changes: 24 additions & 3 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,34 @@ func Run(ctx context.Context, options Options) error {
//
// We need to change the ownership of the files to the user that will
// be running the init script.
filepath.Walk(options.WorkspaceFolder, func(path string, info os.FileInfo, err error) error {
if chownErr := filepath.Walk(options.WorkspaceFolder, func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
return os.Chown(path, userInfo.uid, userInfo.gid)
})
endStage("👤 Updated the ownership of the workspace!")
}); chownErr != nil {
options.Logger(notcodersdk.LogLevelError, "chown %q: %s", userInfo.user.HomeDir, chownErr.Error())
endStage("⚠️ Failed to the ownership of the workspace, you may need to fix this manually!")
} else {
endStage("👤 Updated the ownership of the workspace!")
}
}

// We may also need to update the ownership of the user homedir.
// Skip this step if the user is root.
if userInfo.uid != 0 {
endStage := startStage("🔄 Updating ownership of %s...", userInfo.user.HomeDir)
if chownErr := filepath.Walk(userInfo.user.HomeDir, func(path string, _ fs.FileInfo, err error) error {
if err != nil {
return err
}
return os.Chown(path, userInfo.uid, userInfo.gid)
}); chownErr != nil {
options.Logger(notcodersdk.LogLevelError, "chown %q: %s", userInfo.user.HomeDir, chownErr.Error())
endStage("⚠️ Failed to update ownership of %s, you may need to fix this manually!", userInfo.user.HomeDir)
} else {
endStage("🏡 Updated ownership of %s!", userInfo.user.HomeDir)
}
}

err = os.MkdirAll(options.WorkspaceFolder, 0o755)
Expand Down