Skip to content

Commit b345bfc

Browse files
authored
Apply mode flags on directories (#103)
This repairs the permissions on folders by leveraging the loop that reverts the mtime on the directory after unpacking the files to run chmods on the directories as well
1 parent 90bb99a commit b345bfc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

decompress_tar.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ func untar(input io.Reader, dst, src string, dir bool) error {
101101
}
102102
}
103103

104-
// Adding a file or subdirectory changes the mtime of a directory
105-
// We therefore wait until we've extracted everything and then set the mtime and atime attributes
104+
// Perform a final pass over extracted directories to update metadata
106105
for _, dirHdr := range dirHdrs {
107106
path := filepath.Join(dst, dirHdr.Name)
107+
// Chmod the directory since they might be created before we know the mode flags
108+
if err := os.Chmod(path, dirHdr.FileInfo().Mode()); err != nil {
109+
return err
110+
}
111+
// Set the mtime/atime attributes since they would have been changed during extraction
108112
if err := os.Chtimes(path, dirHdr.AccessTime, dirHdr.ModTime); err != nil {
109113
return err
110114
}

0 commit comments

Comments
 (0)