Skip to content

Commit

Permalink
Merge pull request #1140 from mtrmac/create-no-duplicates
Browse files Browse the repository at this point in the history
(Alternative to 1148): Don't blindly reuse state from a previous layer when re-creating it
  • Loading branch information
rhatdan committed May 2, 2022
2 parents 754b868 + 2a3194c commit f6fd87f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/overlay/overlay.go
Expand Up @@ -939,6 +939,16 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, disable
rootUID = int(st.UID())
rootGID = int(st.GID())
}

if _, err := system.Lstat(dir); err == nil {
logrus.Warnf("Trying to create a layer %#v while directory %q already exists; removing it first", id, dir)
// Don’t just os.RemoveAll(dir) here; d.Remove also removes the link in linkDir,
// so that we can’t end up with two symlinks in linkDir pointing to the same layer.
if err := d.Remove(id); err != nil {
return errors.Wrapf(err, "removing a pre-existing layer directory %q", dir)
}
}

if err := idtools.MkdirAllAndChownNew(dir, 0700, idPair); err != nil {
return err
}
Expand Down

0 comments on commit f6fd87f

Please sign in to comment.