-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fixed permission issues on client #1960
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,24 +313,23 @@ func (d *AllocDir) Embed(task string, entries map[string]string) error { | |
|
||
// Embedding a single file | ||
if !s.IsDir() { | ||
destDir := filepath.Join(taskdir, filepath.Dir(dest)) | ||
if err := os.MkdirAll(destDir, s.Mode().Perm()); err != nil { | ||
return fmt.Errorf("Couldn't create destination directory %v: %v", destDir, err) | ||
if err := d.createDir(taskdir, filepath.Dir(dest)); err != nil { | ||
return fmt.Errorf("Couldn't create destination directory 11 %v: %v", dest, err) | ||
} | ||
|
||
// Copy the file. | ||
taskEntry := filepath.Join(destDir, filepath.Base(dest)) | ||
taskEntry := filepath.Join(taskdir, dest) | ||
if err := d.linkOrCopy(source, taskEntry, s.Mode().Perm()); err != nil { | ||
return err | ||
} | ||
|
||
continue | ||
} | ||
|
||
// Create destination directory. | ||
destDir := filepath.Join(taskdir, dest) | ||
if err := os.MkdirAll(destDir, s.Mode().Perm()); err != nil { | ||
return fmt.Errorf("Couldn't create destination directory %v: %v", destDir, err) | ||
// Create destination directory. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move the comment above or leave a blank line in-between |
||
if err := d.createDir(taskdir, dest); err != nil { | ||
return fmt.Errorf("Couldn't create destination directory 22 %v: %v", destDir, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 22 |
||
} | ||
|
||
// Enumerate the files in source. | ||
|
@@ -565,3 +564,56 @@ func (d *AllocDir) GetSecretDir(task string) (string, error) { | |
return filepath.Join(t, TaskSecrets), nil | ||
} | ||
} | ||
|
||
// createDir creates a directory structure inside the basepath. This functions | ||
// preserves the permissions of each of the subdirectories in the relative path | ||
// by looking up the permissions in the host. | ||
func (d *AllocDir) createDir(basePath, relPath string) error { | ||
filePerms, err := d.splitPath(relPath) | ||
if err != nil { | ||
return err | ||
} | ||
for i := len(filePerms) - 1; i >= 0; i-- { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment why you are going backwards |
||
fi := filePerms[i] | ||
destDir := filepath.Join(basePath, fi.Name) | ||
if err := os.MkdirAll(destDir, fi.Perm); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// fileInfo holds the path and the permissions of a file | ||
type fileInfo struct { | ||
Name string | ||
Perm os.FileMode | ||
} | ||
|
||
// splitPath stats each subdirectory of a path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order that is returned? |
||
func (d *AllocDir) splitPath(path string) ([]fileInfo, error) { | ||
var mode os.FileMode | ||
i, err := os.Stat(path) | ||
if err != nil { | ||
mode = os.ModePerm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment what this is doing |
||
} else { | ||
mode = i.Mode() | ||
} | ||
var dirs []fileInfo | ||
dirs = append(dirs, fileInfo{Name: path, Perm: mode}) | ||
currentDir := path | ||
for { | ||
dir := filepath.Dir(filepath.Clean(currentDir)) | ||
if dir == currentDir { | ||
break | ||
} | ||
i, err = os.Stat(dir) | ||
if err != nil { | ||
mode = os.ModePerm | ||
} else { | ||
mode = i.Mode() | ||
} | ||
dirs = append(dirs, fileInfo{Name: dir, Perm: mode}) | ||
currentDir = dir | ||
} | ||
return dirs, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directory 11?