Skip to content

Commit d5aebde

Browse files
Merge pull request #2580 from HusterWan/zr/fix-read-empty-timestamp
bugfix: updatedAt timestamp file may be empty
2 parents a09bad5 + 92243ff commit d5aebde

35 files changed

+159
-589
lines changed

content/local/store.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"github.com/containerd/containerd/errdefs"
3434
"github.com/containerd/containerd/filters"
3535
"github.com/containerd/containerd/log"
36+
37+
"github.com/containerd/continuity"
3638
digest "github.com/opencontainers/go-digest"
3739
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3840
"github.com/pkg/errors"
@@ -651,5 +653,5 @@ func writeTimestampFile(p string, t time.Time) error {
651653
return err
652654
}
653655

654-
return ioutil.WriteFile(p, b, 0666)
656+
return continuity.AtomicWriteFile(p, b, 0666)
655657
}

content/local/store_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/containerd/containerd/content"
3737
"github.com/containerd/containerd/content/testsuite"
3838
"github.com/containerd/containerd/pkg/testutil"
39+
3940
"github.com/opencontainers/go-digest"
4041
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
4142
"gotest.tools/assert"
@@ -392,3 +393,24 @@ func setupIncompleteWrite(ctx context.Context, t *testing.T, cs content.Store, r
392393

393394
assert.NilError(t, writer.Close())
394395
}
396+
397+
func TestWriteReadEmptyFileTimestamp(t *testing.T) {
398+
root, err := ioutil.TempDir("", "test-write-read-file-timestamp")
399+
if err != nil {
400+
t.Errorf("failed to create a tmp dir: %v", err)
401+
}
402+
defer os.RemoveAll(root)
403+
404+
emptyFile := filepath.Join(root, "updatedat")
405+
if err := writeTimestampFile(emptyFile, time.Time{}); err != nil {
406+
t.Errorf("failed to write Zero Time to file: %v", err)
407+
}
408+
409+
timestamp, err := readFileTimestamp(emptyFile)
410+
if err != nil {
411+
t.Errorf("read empty timestamp file should success, but got error: %v", err)
412+
}
413+
if !timestamp.IsZero() {
414+
t.Errorf("read empty timestamp file should return time.Time{}, but got: %v", timestamp)
415+
}
416+
}

snapshots/btrfs/btrfs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/containerd/containerd/snapshots"
3434
"github.com/containerd/containerd/snapshots/storage"
3535
"github.com/containerd/continuity/fs"
36+
3637
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3738
"github.com/pkg/errors"
3839
"github.com/sirupsen/logrus"
@@ -171,7 +172,7 @@ func (b *snapshotter) usage(ctx context.Context, key string) (snapshots.Usage, e
171172
if parentID != "" {
172173
du, err = fs.DiffUsage(ctx, filepath.Join(b.root, "snapshots", parentID), p)
173174
} else {
174-
du, err = fs.DiskUsage(p)
175+
du, err = fs.DiskUsage(ctx, p)
175176
}
176177
if err != nil {
177178
// TODO(stevvooe): Consider not reporting an error in this case.

snapshots/native/native.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/containerd/containerd/plugin"
2929
"github.com/containerd/containerd/snapshots"
3030
"github.com/containerd/containerd/snapshots/storage"
31+
3132
"github.com/containerd/continuity/fs"
3233
"github.com/pkg/errors"
3334
)
@@ -120,7 +121,7 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, e
120121
}
121122

122123
if info.Kind == snapshots.KindActive {
123-
du, err := fs.DiskUsage(o.getSnapshotDir(id))
124+
du, err := fs.DiskUsage(ctx, o.getSnapshotDir(id))
124125
if err != nil {
125126
return snapshots.Usage{}, err
126127
}
@@ -166,7 +167,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
166167
return err
167168
}
168169

169-
usage, err := fs.DiskUsage(o.getSnapshotDir(id))
170+
usage, err := fs.DiskUsage(ctx, o.getSnapshotDir(id))
170171
if err != nil {
171172
return err
172173
}

snapshots/overlay/overlay.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, e
168168
upperPath := o.upperPath(id)
169169

170170
if info.Kind == snapshots.KindActive {
171-
du, err := fs.DiskUsage(upperPath)
171+
du, err := fs.DiskUsage(ctx, upperPath)
172172
if err != nil {
173173
// TODO(stevvooe): Consider not reporting an error in this case.
174174
return snapshots.Usage{}, err
@@ -225,7 +225,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
225225
return err
226226
}
227227

228-
usage, err := fs.DiskUsage(o.upperPath(id))
228+
usage, err := fs.DiskUsage(ctx, o.upperPath(id))
229229
if err != nil {
230230
return err
231231
}

vendor.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ github.com/containerd/cgroups 5e610833b72089b37d0e615de9a92dfc043757c2
44
github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40
55
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
66
github.com/containerd/btrfs 2e1aa0ddf94f91fa282b6ed87c23bf0d64911244
7-
github.com/containerd/continuity d3c23511c1bf5851696cba83143d9cbcd666869b
7+
github.com/containerd/continuity f44b615e492bdfb371aae2f76ec694d9da1db537
88
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
99
github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098
1010
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
@@ -85,4 +85,4 @@ github.com/mistifyio/go-zfs 166add352731e515512690329794ee593f1aaff2
8585
github.com/pborman/uuid c65b2f87fee37d1c7854c9164a450713c28d50cd
8686

8787
# aufs dependencies
88-
github.com/containerd/aufs a7fbd554da7a9eafbe5a460a421313a9fd18d988
88+
github.com/containerd/aufs ffa39970e26ad01d81f540b21e65f9c1841a5f92

vendor/github.com/containerd/aufs/aufs.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/context.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/driver/driver_unix.go

-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/driver/lchmod_linux.go

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/driver/lchmod_unix.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/fs/du.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/fs/du_unix.go

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/fs/du_windows.go

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/ioutils.go

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/sysx/README.md

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/continuity/sysx/asm.s

-10
This file was deleted.

vendor/github.com/containerd/continuity/sysx/chmod_darwin.go

-18
This file was deleted.

0 commit comments

Comments
 (0)