Skip to content

Commit

Permalink
Fix for #3674 Can't rm containers when disk full
Browse files Browse the repository at this point in the history
Rather than creating a new directory and moving it there before
deleting that new directory, just move the directory we intend to
delete.

In the old way, the Mkdirall could fail, which meant that you
couldn't delete containers when the disk was full.

Tested.

Docker-DCO-1.1-Signed-off-by: Peter Waller <p@pwaller.net> (github: pwaller)
  • Loading branch information
pwaller committed Jan 27, 2014
1 parent ffdc2d2 commit 6f3d8d3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions graphdriver/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,17 @@ func (a *Driver) Remove(id string) error {
"diff",
}

// Remove the dirs atomically
// Atomically remove each directory in turn by first moving it out of the
// way (so that docker doesn't find it anymore) before doing removal of
// the whole tree.
for _, p := range tmpDirs {
// We need to use a temp dir in the same dir as the driver so Rename
// does not fall back to the slow copy if /tmp and the driver dir
// are on different devices
tmp := path.Join(a.rootPath(), "tmp", p, id)
if err := os.MkdirAll(tmp, 0755); err != nil {
return err
}

realPath := path.Join(a.rootPath(), p, id)
if err := os.Rename(realPath, tmp); err != nil && !os.IsNotExist(err) {
tmpPath := path.Join(a.rootPath(), p, fmt.Sprintf("%s-removing", id))
if err := os.Rename(realPath, tmpPath); err != nil && !os.IsNotExist(err) {
return err
}
defer os.RemoveAll(tmp)
defer os.RemoveAll(tmpPath)
}

// Remove the layers file for the id
Expand Down

0 comments on commit 6f3d8d3

Please sign in to comment.