Skip to content

Commit

Permalink
Merge pull request moby#46471 from foundriesio/atomic-layer-data-write
Browse files Browse the repository at this point in the history
daemon: overlay2: Write layer metadata atomically
  • Loading branch information
thaJeztah authored Sep 14, 2023
2 parents 39b2bf5 + de2447c commit 01cc1cc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions daemon/graphdriver/overlay2/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/directory"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/quota"
units "github.com/docker/go-units"
Expand Down Expand Up @@ -383,7 +384,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr
}

// Write link id to link file
if err := os.WriteFile(path.Join(dir, "link"), []byte(lid), 0o644); err != nil {
if err := ioutils.AtomicWriteFile(path.Join(dir, "link"), []byte(lid), 0o644); err != nil {
return err
}

Expand All @@ -396,7 +397,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr
return err
}

if err := os.WriteFile(path.Join(d.dir(parent), "committed"), []byte{}, 0o600); err != nil {
if err := ioutils.AtomicWriteFile(path.Join(d.dir(parent), "committed"), []byte{}, 0o600); err != nil {
return err
}

Expand All @@ -405,7 +406,7 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr
return err
}
if lower != "" {
if err := os.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0o666); err != nil {
if err := ioutils.AtomicWriteFile(path.Join(dir, lowerFile), []byte(lower), 0o666); err != nil {
return err
}
}
Expand Down

0 comments on commit 01cc1cc

Please sign in to comment.