Merge pull request #698 from dmcgowan/snapshot-mkdir-exist

Update snapshot mkdir to check for directory exist
This commit is contained in:
Qiang Huang 2017-04-06 17:08:22 +08:00 committed by GitHub
commit 0a484cc5dc
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
}