Skip to content

Commit dc34277

Browse files
committed
Change Chown to point to the real files just written by the atomic
writter Signed-off-by: joshvanl <[email protected]>
1 parent e4f097e commit dc34277

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

storage/filesystem.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (f *Filesystem) RegisterMetadata(meta metadata.Metadata) (bool, error) {
193193
// data directory. Filesystem supports changing ownership of the data directory
194194
// to a custom gid.
195195
func (f *Filesystem) WriteFiles(meta metadata.Metadata, files map[string][]byte) error {
196-
// Data directory should be read, write and execute only to the fs user; read and executable to group
196+
// Data directory should be read and execute only to the fs user and group.
197197
if err := os.MkdirAll(f.dataPathForVolumeID(meta.VolumeID), 0550); err != nil {
198198
return err
199199
}
@@ -220,17 +220,16 @@ func (f *Filesystem) WriteFiles(meta metadata.Metadata, files map[string][]byte)
220220
return err
221221
}
222222

223-
// If a fsGroup is defined, Chown all files within the data directory.
223+
// If a fsGroup is defined, Chown all files just written.
224224
if fsGroup != nil {
225-
dirName := f.dataPathForVolumeID(meta.VolumeID)
226-
entries, err := os.ReadDir(dirName)
227-
if err != nil {
228-
return fmt.Errorf("failed to list files in data directory: %w", err)
229-
}
225+
// "..data" is the well-known location where the atomic writer links to the
226+
// latest directory containing the files just written. Chown these real
227+
// files.
228+
dirName := filepath.Join(f.dataPathForVolumeID(meta.VolumeID), "..data")
230229

231-
for _, entry := range entries {
230+
for filename := range files {
232231
// Set the uid to -1 which means don't change ownership in Go.
233-
if err := os.Chown(filepath.Join(dirName, entry.Name()), -1, int(*fsGroup)); err != nil {
232+
if err := os.Chown(filepath.Join(dirName, filename), -1, int(*fsGroup)); err != nil {
234233
return err
235234
}
236235
}
@@ -311,7 +310,7 @@ func (f *Filesystem) fsGroupForMetadata(meta metadata.Metadata) (*int64, error)
311310
// fsGroup has to be between 1 and 4294967295 inclusive. 4294967295 is the
312311
// largest gid number on most modern operating systems. If the actual maximum
313312
// is smaller on the running machine, then we will simply error later during
314-
// the Chmod.
313+
// the Chown.
315314
if fsGroup <= 0 || fsGroup > 4294967295 {
316315
return nil, fmt.Errorf("%q: gid value must be greater than 0 and less than 4294967295: %d", f.FSGroupVolumeAttributeKey, fsGroup)
317316
}

0 commit comments

Comments
 (0)