Skip to content

Commit

Permalink
fix: cleanup volume dir if create volume failed
Browse files Browse the repository at this point in the history
Volume path should be cleaned up if create volume failed.
Otherwise, the volume will be created failed again next time
with a 'file exists' error on os.Mkdir.

Signed-off-by: baijia <baijia.wr@antgroup.com>
  • Loading branch information
白加 committed Mar 8, 2024
1 parent faf83fc commit 58aa314
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/mountutil/volumestore/volumestore.go
Expand Up @@ -83,13 +83,23 @@ func (vs *volumeStore) Create(name string, labels []string) (*native.Volume, err
}
volPath := filepath.Join(vs.dir, name)
volDataPath := filepath.Join(volPath, DataDirName)
fn := func() error {
fn := func() (err error) {
if err := os.Mkdir(volPath, 0700); err != nil {
return err
}
defer func() {
if err != nil {
os.Remove(volPath)
}
}()
if err := os.Mkdir(volDataPath, 0755); err != nil {
return err
}
defer func() {
if err != nil {
os.Remove(volDataPath)
}
}()

type volumeOpts struct {
Labels map[string]string `json:"labels"`
Expand Down

0 comments on commit 58aa314

Please sign in to comment.