From 14cab0fff0948fa243a1331bd7c1041aadc2c6ec Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 4 May 2020 12:17:46 +0100 Subject: [PATCH] local: fix "file not found" errors on post transfer Hash calculation Before this change the local backend was returning file not found errors for post transfer hashes for files which were moved. This was caused by the routine which checks for the object being changed. After this change we ignore file not found errors while checking to see if the object has changed. If the hash has to be computed then a file not found error will be thrown when it is opened, otherwise the cached hash will be returned. --- backend/local/local.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/local/local.go b/backend/local/local.go index 126edd4d0..bcd6d9b68 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -768,8 +768,17 @@ func (o *Object) Hash(ctx context.Context, r hash.Type) (string, error) { oldtime := o.modTime oldsize := o.size err := o.lstat() + var changed bool if err != nil { - return "", errors.Wrap(err, "hash: failed to stat") + if os.IsNotExist(errors.Cause(err)) { + // If file not found then we assume any accumulated + // hashes are OK - this will error on Open + changed = true + } else { + return "", errors.Wrap(err, "hash: failed to stat") + } + } else { + changed = !o.modTime.Equal(oldtime) || oldsize != o.size } o.fs.objectHashesMu.Lock() @@ -777,7 +786,7 @@ func (o *Object) Hash(ctx context.Context, r hash.Type) (string, error) { hashValue, hashFound := o.hashes[r] o.fs.objectHashesMu.Unlock() - if !o.modTime.Equal(oldtime) || oldsize != o.size || hashes == nil || !hashFound { + if changed || hashes == nil || !hashFound { var in io.ReadCloser if !o.translatedLink {