Skip to content

Commit 2e92b6c

Browse files
committed
ListVolumes: switch to using 'Stat' rather than 'Open'
Signed-off-by: James Munnelly <[email protected]>
1 parent 8799580 commit 2e92b6c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

storage/filesystem.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Filesystem struct {
4747
baseDir string
4848

4949
// used by the 'read only' methods
50-
fs fs.FS
50+
fs fs.StatFS
5151

5252
// FixedFSGroup is an optional field which will set the gid ownership of all
5353
// volume's data directories to this value.
@@ -71,7 +71,7 @@ func NewFilesystem(log logr.Logger, baseDir string) (*Filesystem, error) {
7171
baseDir: baseDir,
7272
// Use the rootfs as the DirFS so that paths passed to both read &
7373
// write methods on this struct use a consistent root.
74-
fs: os.DirFS("/"),
74+
fs: os.DirFS("/").(fs.StatFS),
7575
}
7676

7777
notMnt, err := mount.IsNotMountPoint(mount.New(""), f.tempfsPath())
@@ -110,7 +110,7 @@ func (f *Filesystem) ListVolumes() ([]string, error) {
110110

111111
var vols []string
112112
for _, dir := range dirs {
113-
file, err := f.fs.Open(f.metadataPathForVolumeID(dir.Name()))
113+
_, err := f.fs.Stat(f.metadataPathForVolumeID(dir.Name()))
114114
switch {
115115
case errors.Is(err, fs.ErrNotExist):
116116
f.log.Info("Directory exists but does not contain a metadata file - deleting directory and its contents", "volume_id", dir.Name())
@@ -123,8 +123,6 @@ func (f *Filesystem) ListVolumes() ([]string, error) {
123123
// discovered a volume/directory that does not contain a metadata file
124124
return nil, err
125125
}
126-
// immediately close the file as we just need to verify it exists
127-
file.Close()
128126
vols = append(vols, dir.Name())
129127
}
130128

0 commit comments

Comments
 (0)