bugfix: updatedAt timestamp file may be empty
Signed-off-by: Michael Wan <zirenwan@gmail.com>
This commit is contained in:
@@ -33,6 +33,8 @@ import (
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/filters"
|
||||
"github.com/containerd/containerd/log"
|
||||
|
||||
"github.com/containerd/continuity"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
@@ -651,5 +653,5 @@ func writeTimestampFile(p string, t time.Time) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(p, b, 0666)
|
||||
return continuity.AtomicWriteFile(p, b, 0666)
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/content/testsuite"
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"gotest.tools/assert"
|
||||
@@ -392,3 +393,24 @@ func setupIncompleteWrite(ctx context.Context, t *testing.T, cs content.Store, r
|
||||
|
||||
assert.NilError(t, writer.Close())
|
||||
}
|
||||
|
||||
func TestWriteReadEmptyFileTimestamp(t *testing.T) {
|
||||
root, err := ioutil.TempDir("", "test-write-read-file-timestamp")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create a tmp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
emptyFile := filepath.Join(root, "updatedat")
|
||||
if err := writeTimestampFile(emptyFile, time.Time{}); err != nil {
|
||||
t.Errorf("failed to write Zero Time to file: %v", err)
|
||||
}
|
||||
|
||||
timestamp, err := readFileTimestamp(emptyFile)
|
||||
if err != nil {
|
||||
t.Errorf("read empty timestamp file should success, but got error: %v", err)
|
||||
}
|
||||
if !timestamp.IsZero() {
|
||||
t.Errorf("read empty timestamp file should return time.Time{}, but got: %v", timestamp)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user