Update snapshot mkdir to check for directory exist

When starting up a snapshot driver on subsequent runs, the
mkdir call will return an exist error, this can be safely
ignored.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-04-05 17:04:44 -07:00
parent 56972bf915
commit 63f01733b0
No known key found for this signature in database
GPG key ID: F58C5D0A4405ACDB
3 changed files with 7 additions and 3 deletions

View file

@ -46,6 +46,10 @@ type snapshotter struct {
// device and root directory for snapshots and stores the metadata in
// a file in the provided root.
func NewSnapshotter(device, root string) (snapshot.Snapshotter, error) {
if err := os.MkdirAll(root, 0700); err != nil {
return nil, err
}
var (
active = filepath.Join(root, "active")
snapshots = filepath.Join(root, "snapshots")
@ -55,7 +59,7 @@ func NewSnapshotter(device, root string) (snapshot.Snapshotter, error) {
active,
snapshots,
} {
if err := os.MkdirAll(path, 0755); err != nil {
if err := os.Mkdir(path, 0755); err != nil && !os.IsExist(err) {
return nil, err
}
}

View file

@ -40,7 +40,7 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
return nil, err
}
if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil {
if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
return nil, err
}

View file

@ -49,7 +49,7 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
return nil, err
}
if err := os.MkdirAll(filepath.Join(root, "snapshots"), 0700); err != nil {
if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
return nil, err
}