Skip to content

Commit

Permalink
Fix etag changing only once a second (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck authored Mar 23, 2021
1 parent 280aa19 commit c5ec249
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-etag-changing-only-every-second.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix etag changing only once a second

We fixed a problem with the owncloud storage driver only considering
the mtime with a second resolution for the etag calculation.

https://github.com/cs3org/reva/pull/1576
2 changes: 1 addition & 1 deletion pkg/storage/fs/owncloud/owncloud_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
func calcEtag(ctx context.Context, fi os.FileInfo) string {
log := appctx.GetLogger(ctx)
h := md5.New()
err := binary.Write(h, binary.BigEndian, fi.ModTime().Unix())
err := binary.Write(h, binary.BigEndian, fi.ModTime().UnixNano())
if err != nil {
log.Error().Err(err).Msg("error writing mtime")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/owncloud/owncloud_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
func calcEtag(ctx context.Context, fi os.FileInfo) string {
log := appctx.GetLogger(ctx)
h := md5.New()
err := binary.Write(h, binary.BigEndian, fi.ModTime().Unix())
err := binary.Write(h, binary.BigEndian, fi.ModTime().UnixNano())
if err != nil {
log.Error().Err(err).Msg("error writing mtime")
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/storage/utils/decomposedfs/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package node_test

import (
"time"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
helpers "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/testhelpers"
Expand Down Expand Up @@ -147,4 +149,38 @@ var _ = Describe("Node", func() {
Expect(child.Blobsize).To(Equal(int64(1234)))
})
})

Describe("AsResourceInfo", func() {
var (
n *node.Node
)

BeforeEach(func() {
var err error
n, err = env.Lookup.NodeFromPath(env.Ctx, "dir1/file1")
Expect(err).ToNot(HaveOccurred())
})

Describe("the Etag field", func() {
It("is set", func() {
ri, err := n.AsResourceInfo(env.Ctx, node.OwnerPermissions, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(len(ri.Etag)).To(Equal(34))
})

It("changes when the tmtime is set", func() {
ri, err := n.AsResourceInfo(env.Ctx, node.OwnerPermissions, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(len(ri.Etag)).To(Equal(34))
before := ri.Etag

Expect(n.SetTMTime(time.Now().UTC())).To(Succeed())

ri, err = n.AsResourceInfo(env.Ctx, node.OwnerPermissions, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(len(ri.Etag)).To(Equal(34))
Expect(ri.Etag).ToNot(Equal(before))
})
})
})
})
17 changes: 17 additions & 0 deletions pkg/storage/utils/decomposedfs/tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ var _ = Describe("Tree", func() {
Expect(err).ToNot(HaveOccurred())
})

Describe("with TreeTimeAccounting enabled", func() {
It("sets the tmtime of the parent", func() {
file, err := env.CreateTestFile("file1", "", 1, dir.ID)
Expect(err).ToNot(HaveOccurred())

riBefore, err := dir.AsResourceInfo(env.Ctx, node.OwnerPermissions, []string{})
Expect(err).ToNot(HaveOccurred())

err = env.Tree.Propagate(env.Ctx, file)
Expect(err).ToNot(HaveOccurred())

riAfter, err := dir.AsResourceInfo(env.Ctx, node.OwnerPermissions, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(riAfter.Etag).ToNot(Equal(riBefore.Etag))
})
})

Describe("with TreeSizeAccounting enabled", func() {
It("calculates the size", func() {
file, err := env.CreateTestFile("file1", "", 1, dir.ID)
Expand Down

0 comments on commit c5ec249

Please sign in to comment.