Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix etag propagation in ocis driver #1264

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/ocis-fix-etag-propagation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix etag propagation in ocis driver

We now use a new synctime timestamp instead of trying to read the mtime to avoid race conditions when the stat request happens too quickly.

https://github.com/cs3org/reva/pull/1264
https://github.com/owncloud/product/issues/249
35 changes: 20 additions & 15 deletions pkg/storage/fs/ocis/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,15 @@ func (t *Tree) Propagate(ctx context.Context, n *Node) (err error) {
}
log := appctx.GetLogger(ctx)

nodePath := t.lu.toInternalPath(n.ID)

// is propagation enabled for the parent node?

var root *Node
if root, err = t.lu.HomeOrRootNode(ctx); err != nil {
return
}

var fi os.FileInfo
if fi, err = os.Stat(nodePath); err != nil {
return err
}

var b []byte
// use a sync time and don't rely on the mtime of the current node, as the stat might not change when a rename happened too quickly
sTime := time.Now().UTC()

for err == nil && n.ID != root.ID {
log.Debug().Interface("node", n).Msg("propagating")
Expand All @@ -355,22 +349,33 @@ func (t *Tree) Propagate(ctx context.Context, n *Node) (err error) {
switch {
case err != nil:
// missing attribute, or invalid format, overwrite
log.Error().Err(err).Interface("node", n).Msg("could not read tmtime attribute, overwriting")
log.Error().Err(err).
Interface("node", n).
Msg("could not read tmtime attribute, overwriting")
updateSyncTime = true
case tmTime.Before(fi.ModTime()):
log.Debug().Interface("node", n).Str("tmtime", string(b)).Str("mtime", fi.ModTime().UTC().Format(time.RFC3339Nano)).Msg("parent tmtime is older than node mtime, updating")
case tmTime.Before(sTime):
log.Debug().
Interface("node", n).
Time("tmtime", tmTime).
Time("stime", sTime).
Msg("parent tmtime is older than node mtime, updating")
updateSyncTime = true
default:
log.Debug().Interface("node", n).Str("tmtime", string(b)).Str("mtime", fi.ModTime().UTC().Format(time.RFC3339Nano)).Msg("parent tmtime is younger than node mtime, not updating")
log.Debug().
Interface("node", n).
Time("tmtime", tmTime).
Time("stime", sTime).
Dur("delta", sTime.Sub(tmTime)).
Msg("parent tmtime is younger than node mtime, not updating")
}

if updateSyncTime {
// update the tree time of the parent node
if err = n.SetTMTime(fi.ModTime()); err != nil {
log.Error().Err(err).Interface("node", n).Time("tmtime", fi.ModTime().UTC()).Msg("could not update tmtime of parent node")
if err = n.SetTMTime(sTime); err != nil {
log.Error().Err(err).Interface("node", n).Time("tmtime", sTime).Msg("could not update tmtime of parent node")
return
}
log.Debug().Interface("node", n).Time("tmtime", fi.ModTime().UTC()).Msg("updated tmtime of parent node")
log.Debug().Interface("node", n).Time("tmtime", sTime).Msg("updated tmtime of parent node")
}

if err := n.UnsetTempEtag(); err != nil {
Expand Down