@@ -193,7 +193,7 @@ func (f *Filesystem) RegisterMetadata(meta metadata.Metadata) (bool, error) {
193
193
// data directory. Filesystem supports changing ownership of the data directory
194
194
// to a custom gid.
195
195
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.
197
197
if err := os .MkdirAll (f .dataPathForVolumeID (meta .VolumeID ), 0550 ); err != nil {
198
198
return err
199
199
}
@@ -220,17 +220,16 @@ func (f *Filesystem) WriteFiles(meta metadata.Metadata, files map[string][]byte)
220
220
return err
221
221
}
222
222
223
- // If a fsGroup is defined, Chown all files within the data directory .
223
+ // If a fsGroup is defined, Chown all files just written .
224
224
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" )
230
229
231
- for _ , entry := range entries {
230
+ for filename := range files {
232
231
// 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 {
234
233
return err
235
234
}
236
235
}
@@ -311,7 +310,7 @@ func (f *Filesystem) fsGroupForMetadata(meta metadata.Metadata) (*int64, error)
311
310
// fsGroup has to be between 1 and 4294967295 inclusive. 4294967295 is the
312
311
// largest gid number on most modern operating systems. If the actual maximum
313
312
// is smaller on the running machine, then we will simply error later during
314
- // the Chmod .
313
+ // the Chown .
315
314
if fsGroup <= 0 || fsGroup > 4294967295 {
316
315
return nil , fmt .Errorf ("%q: gid value must be greater than 0 and less than 4294967295: %d" , f .FSGroupVolumeAttributeKey , fsGroup )
317
316
}
0 commit comments