@@ -47,7 +47,7 @@ type Filesystem struct {
47
47
baseDir string
48
48
49
49
// used by the 'read only' methods
50
- fs fs.FS
50
+ fs fs.StatFS
51
51
52
52
// FixedFSGroup is an optional field which will set the gid ownership of all
53
53
// volume's data directories to this value.
@@ -71,7 +71,7 @@ func NewFilesystem(log logr.Logger, baseDir string) (*Filesystem, error) {
71
71
baseDir : baseDir ,
72
72
// Use the rootfs as the DirFS so that paths passed to both read &
73
73
// write methods on this struct use a consistent root.
74
- fs : os .DirFS ("/" ),
74
+ fs : os .DirFS ("/" ).(fs. StatFS ) ,
75
75
}
76
76
77
77
notMnt , err := mount .IsNotMountPoint (mount .New ("" ), f .tempfsPath ())
@@ -110,14 +110,19 @@ func (f *Filesystem) ListVolumes() ([]string, error) {
110
110
111
111
var vols []string
112
112
for _ , dir := range dirs {
113
- file , err := f .fs .Open (f .metadataPathForVolumeID (dir .Name ()))
114
- if err != nil {
113
+ _ , err := f .fs .Stat (f .metadataPathForVolumeID (dir .Name ()))
114
+ switch {
115
+ case errors .Is (err , fs .ErrNotExist ):
116
+ f .log .Info ("Directory exists but does not contain a metadata file - deleting directory and its contents" , "volume_id" , dir .Name ())
117
+ if err := f .RemoveVolume (dir .Name ()); err != nil {
118
+ return nil , fmt .Errorf ("deleting stale volume: %v" , err )
119
+ }
120
+ // continue to skip this loop iteration
121
+ continue
122
+ case err != nil :
115
123
// discovered a volume/directory that does not contain a metadata file
116
- // TODO: log this error to allow startup to continue
117
124
return nil , err
118
125
}
119
- // immediately close the file as we just need to verify it exists
120
- file .Close ()
121
126
vols = append (vols , dir .Name ())
122
127
}
123
128
0 commit comments