Skip to content

Commit

Permalink
fix directory ownership
Browse files Browse the repository at this point in the history
Signed-off-by: Rutik7066 <[email protected]>
  • Loading branch information
Rutik7066 committed Jan 27, 2025
1 parent 232c7c7 commit d136bb4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"os"
"os/exec"
"runtime"
"time"

"github.com/daytonaio/daytona/cmd/daytona/config"
Expand Down Expand Up @@ -118,10 +119,26 @@ func (a *Agent) startWorkspaceMode() error {
log.Error(err)
}
if ownerUid != uint32(os.Getuid()) {
chownCmd := exec.Command("sudo", "chown", "-R", fmt.Sprintf("%s:%s", a.Workspace.User, a.Workspace.User), a.Config.WorkspaceDir)
err = chownCmd.Run()
if err != nil {
log.Error(err)
user := a.Workspace.User
directory := a.Config.WorkspaceDir
if runtime.GOOS == "windows" {
takeownCmd := exec.Command("takeown", "/F", directory, "/R", "/D", "Y")
err := takeownCmd.Run()
if err != nil {
log.Errorf("Failed to take ownership: %v", err)
}

icaclsCmd := exec.Command("icacls", directory, "/grant", fmt.Sprintf("%s:F", user), "/T")
err = icaclsCmd.Run()
if err != nil {
log.Errorf("Failed to grant permissions: %v", err)
}
} else {
chownCmd := exec.Command("sudo", "chown", "-R", fmt.Sprintf("%s:%s", user, user), directory)
err = chownCmd.Run()
if err != nil {
log.Error(err)
}
}
}
}
Expand Down

0 comments on commit d136bb4

Please sign in to comment.