Skip to content

Commit 7363e97

Browse files
authored
Merge pull request #9 from kolyshkin/fix-dir-perms
MkdirAllNewAs,CopyDirectory: ensure dir perms
2 parents d7fdd64 + e3d1947 commit 7363e97

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

fileutils.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func CopyDirectory(source string, dest string) error {
125125
if err != nil {
126126
return nil
127127
}
128+
destPath := filepath.Join(dest, relPath)
128129

129130
if info.IsDir() {
130131
// Skip the source directory.
@@ -138,18 +139,20 @@ func CopyDirectory(source string, dest string) error {
138139
uid := int(st.Uid)
139140
gid := int(st.Gid)
140141

141-
if err := os.Mkdir(filepath.Join(dest, relPath), info.Mode()); err != nil {
142+
if err := os.Mkdir(destPath, info.Mode()); err != nil {
142143
return err
143144
}
144-
145-
if err := os.Lchown(filepath.Join(dest, relPath), uid, gid); err != nil {
145+
if err := os.Lchown(destPath, uid, gid); err != nil {
146+
return err
147+
}
148+
if err := os.Chmod(destPath, info.Mode()); err != nil {
146149
return err
147150
}
148151
}
149152
return nil
150153
}
151154

152-
return CopyFile(path, filepath.Join(dest, relPath))
155+
return CopyFile(path, destPath)
153156
})
154157
}
155158

idtools.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func MkdirAllNewAs(path string, mode os.FileMode, ownerUID, ownerGID int) error
4949
if err := os.Chown(pathComponent, ownerUID, ownerGID); err != nil {
5050
return err
5151
}
52+
if err := os.Chmod(pathComponent, mode); err != nil {
53+
return err
54+
}
5255
}
5356
return nil
5457
}

0 commit comments

Comments
 (0)