Skip to content

Commit cf7fb14

Browse files
committed
Update timestamp atomic write
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 4f6ba82 commit cf7fb14

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

content/local/store.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/containerd/containerd/log"
3636
"github.com/sirupsen/logrus"
3737

38-
"github.com/containerd/continuity"
3938
digest "github.com/opencontainers/go-digest"
4039
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
4140
"github.com/pkg/errors"
@@ -661,6 +660,19 @@ func writeTimestampFile(p string, t time.Time) error {
661660
if err != nil {
662661
return err
663662
}
663+
return atomicWrite(p, b, 0666)
664+
}
664665

665-
return continuity.AtomicWriteFile(p, b, 0666)
666+
func atomicWrite(path string, data []byte, mode os.FileMode) error {
667+
tmp := fmt.Sprintf("%s.tmp", path)
668+
f, err := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, mode)
669+
if err != nil {
670+
return errors.Wrap(err, "create tmp file")
671+
}
672+
_, err = f.Write(data)
673+
f.Close()
674+
if err != nil {
675+
return errors.Wrap(err, "write atomic data")
676+
}
677+
return os.Rename(tmp, path)
666678
}

0 commit comments

Comments
 (0)