@@ -60,10 +60,9 @@ type AtomicWriter struct {
60
60
61
61
// FileProjection contains file Data and access Mode
62
62
type FileProjection struct {
63
- Data []byte
64
- Mode int32
65
- FsUser * int64
66
- FsGroup * int64
63
+ Data []byte
64
+ Mode int32
65
+ FsUser * int64
67
66
}
68
67
69
68
// NewAtomicWriter creates a new AtomicWriter configured to write to the given
@@ -96,14 +95,14 @@ const (
96
95
// data to determine if an update is required.
97
96
// 5. A new timestamped dir is created
98
97
// 6. The payload is written to the new timestamped directory
99
- // 7. Symlinks and directory for new user-group- visible files are created (if needed).
98
+ // 7. Symlinks and directory for new user-visible files are created (if needed).
100
99
//
101
100
// For example, consider the files:
102
101
// <target-dir>/podName
103
- // <target-dir>/user-group /labels
102
+ // <target-dir>/user/labels
104
103
// <target-dir>/k8s/annotations
105
104
//
106
- // The user-group visible files are symbolic links into the internal data directory:
105
+ // The user visible files are symbolic links into the internal data directory:
107
106
// <target-dir>/podName -> ..data/podName
108
107
// <target-dir>/usr -> ..data/usr
109
108
// <target-dir>/k8s -> ..data/k8s
@@ -114,7 +113,7 @@ const (
114
113
// 8. A symlink to the new timestamped directory ..data_tmp is created that will
115
114
// become the new data directory
116
115
// 9. The new data directory symlink is renamed to the data directory; rename is atomic
117
- // 10. Old paths are removed from the user-group- visible portion of the target directory
116
+ // 10. Old paths are removed from the user-visible portion of the target directory
118
117
// 11. The previous timestamped directory is removed, if it exists
119
118
func (w * AtomicWriter ) Write (payload map [string ]FileProjection ) error {
120
119
// (1)
@@ -144,7 +143,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
144
143
// (3)
145
144
pathsToRemove , err = w .pathsToRemove (cleanPayload , oldTsPath )
146
145
if err != nil {
147
- klog .Errorf ("%s: error determining user-group- visible files to remove: %v" , w .logContext , err )
146
+ klog .Errorf ("%s: error determining user-visible files to remove: %v" , w .logContext , err )
148
147
return err
149
148
}
150
149
@@ -176,7 +175,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
176
175
klog .V (4 ).Infof ("%s: performed write of new data to ts data directory: %s" , w .logContext , tsDir )
177
176
178
177
// (7)
179
- if err = w .createGroupVisibleFiles (cleanPayload ); err != nil {
178
+ if err = w .createUserVisibleFiles (cleanPayload ); err != nil {
180
179
klog .Errorf ("%s: error creating visible symlinks in %s: %v" , w .logContext , w .targetDir , err )
181
180
return err
182
181
}
@@ -205,7 +204,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
205
204
}
206
205
207
206
// (10)
208
- if err = w .removeGroupVisiblePaths (pathsToRemove ); err != nil {
207
+ if err = w .removeUserVisiblePaths (pathsToRemove ); err != nil {
209
208
klog .Errorf ("%s: error removing old visible symlinks: %v" , w .logContext , err )
210
209
return err
211
210
}
@@ -277,8 +276,8 @@ func validatePath(targetPath string) error {
277
276
278
277
// shouldWritePayload returns whether the payload should be written to disk.
279
278
func shouldWritePayload (payload map [string ]FileProjection , oldTsDir string ) (bool , error ) {
280
- for userGroupVisiblePath , fileProjection := range payload {
281
- shouldWrite , err := shouldWriteFile (filepath .Join (oldTsDir , userGroupVisiblePath ), fileProjection .Data )
279
+ for userVisiblePath , fileProjection := range payload {
280
+ shouldWrite , err := shouldWriteFile (filepath .Join (oldTsDir , userVisiblePath ), fileProjection .Data )
282
281
if err != nil {
283
282
return false , err
284
283
}
@@ -356,7 +355,7 @@ func (w *AtomicWriter) newTimestampDir() (string, error) {
356
355
return "" , err
357
356
}
358
357
359
- // 0755 permissions are needed to allow 'user ' and 'other' to recurse the
358
+ // 0755 permissions are needed to allow 'group ' and 'other' to recurse the
360
359
// directory tree. do a chmod here to ensure that permissions are set correctly
361
360
// regardless of the process' umask.
362
361
err = os .Chmod (tsDir , 0755 )
@@ -371,10 +370,10 @@ func (w *AtomicWriter) newTimestampDir() (string, error) {
371
370
// writePayloadToDir writes the given payload to the given directory. The
372
371
// directory must exist.
373
372
func (w * AtomicWriter ) writePayloadToDir (payload map [string ]FileProjection , dir string ) error {
374
- for userGroupVisiblePath , fileProjection := range payload {
373
+ for userVisiblePath , fileProjection := range payload {
375
374
content := fileProjection .Data
376
375
mode := os .FileMode (fileProjection .Mode )
377
- fullPath := filepath .Join (dir , userGroupVisiblePath )
376
+ fullPath := filepath .Join (dir , userVisiblePath )
378
377
baseDir , _ := filepath .Split (fullPath )
379
378
380
379
if err := os .MkdirAll (baseDir , os .ModePerm ); err != nil {
@@ -395,31 +394,19 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
395
394
return err
396
395
}
397
396
398
- // If neither FsUser or FsGroup defined, we don't need to Chown.
399
- if fileProjection .FsUser == nil && fileProjection .FsGroup == nil {
397
+ if fileProjection .FsUser == nil {
400
398
continue
401
399
}
402
-
403
- fsUser := - 1
404
- if fileProjection .FsUser != nil {
405
- fsUser = int (* fileProjection .FsUser )
406
- }
407
-
408
- fsGroup := - 1
409
- if fileProjection .FsGroup != nil {
410
- fsGroup = int (* fileProjection .FsGroup )
411
- }
412
-
413
- if err := os .Chown (fullPath , fsUser , fsGroup ); err != nil {
414
- klog .Errorf ("%s: unable to change file %s with group=%v user=%v owner: %v" , w .logContext , fullPath , fsUser , fsGroup , err )
400
+ if err := os .Chown (fullPath , int (* fileProjection .FsUser ), - 1 ); err != nil {
401
+ klog .Errorf ("%s: unable to change file %s with owner %v: %v" , w .logContext , fullPath , int (* fileProjection .FsUser ), err )
415
402
return err
416
403
}
417
404
}
418
405
419
406
return nil
420
407
}
421
408
422
- // createGroupVisibleFiles creates the relative symlinks for all the
409
+ // createUserVisibleFiles creates the relative symlinks for all the
423
410
// files configured in the payload. If the directory in a file path does not
424
411
// exist, it is created.
425
412
//
@@ -429,13 +416,13 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
429
416
// bar -> ..data/bar
430
417
// foo -> ..data/foo
431
418
// baz -> ..data/baz
432
- func (w * AtomicWriter ) createGroupVisibleFiles (payload map [string ]FileProjection ) error {
433
- for userGroupVisiblePath := range payload {
434
- slashpos := strings .Index (userGroupVisiblePath , string (os .PathSeparator ))
419
+ func (w * AtomicWriter ) createUserVisibleFiles (payload map [string ]FileProjection ) error {
420
+ for userVisiblePath := range payload {
421
+ slashpos := strings .Index (userVisiblePath , string (os .PathSeparator ))
435
422
if slashpos == - 1 {
436
- slashpos = len (userGroupVisiblePath )
423
+ slashpos = len (userVisiblePath )
437
424
}
438
- linkname := userGroupVisiblePath [:slashpos ]
425
+ linkname := userVisiblePath [:slashpos ]
439
426
_ , err := os .Readlink (filepath .Join (w .targetDir , linkname ))
440
427
if err != nil && os .IsNotExist (err ) {
441
428
// The link into the data directory for this path doesn't exist; create it
@@ -451,9 +438,9 @@ func (w *AtomicWriter) createGroupVisibleFiles(payload map[string]FileProjection
451
438
return nil
452
439
}
453
440
454
- // removeGroupVisiblePaths removes the set of paths from the user-group -visible
441
+ // removeUserVisiblePaths removes the set of paths from the user-visible
455
442
// portion of the writer's target directory.
456
- func (w * AtomicWriter ) removeGroupVisiblePaths (paths sets.String ) error {
443
+ func (w * AtomicWriter ) removeUserVisiblePaths (paths sets.String ) error {
457
444
ps := string (os .PathSeparator )
458
445
var lasterr error
459
446
for p := range paths {
@@ -462,7 +449,7 @@ func (w *AtomicWriter) removeGroupVisiblePaths(paths sets.String) error {
462
449
continue
463
450
}
464
451
if err := os .Remove (filepath .Join (w .targetDir , p )); err != nil {
465
- klog .Errorf ("%s: error pruning old user-group- visible path %s: %v" , w .logContext , p , err )
452
+ klog .Errorf ("%s: error pruning old user-visible path %s: %v" , w .logContext , p , err )
466
453
lasterr = err
467
454
}
468
455
}
0 commit comments