From 07fcba888cbb7c84b1e568c3e07700e2ee2d8c09 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 31 Oct 2021 19:07:09 +0000 Subject: [PATCH] dircache: add SetRootIDAlias to update RootID from FindLeaf --- lib/dircache/dircache.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/dircache/dircache.go b/lib/dircache/dircache.go index 1b77cfdba..a8c9d3a6f 100644 --- a/lib/dircache/dircache.go +++ b/lib/dircache/dircache.go @@ -126,6 +126,20 @@ func (dc *DirCache) Flush() { dc.cacheMu.Unlock() } +// SetRootIDAlias sets the rootID to that passed in. This assumes that +// the new ID is just an alias for the old ID so does not flush +// anything. +// +// This should be called from FindLeaf (and only from FindLeaf) if it +// is discovered that the root ID is incorrect. For example some +// backends use "0" as a root ID, but it has a real ID which is needed +// for some operations. +func (dc *DirCache) SetRootIDAlias(rootID string) { + // No locking as this is called from FindLeaf + dc.rootID = rootID + dc.Put("", dc.rootID) +} + // FlushDir flushes the map of all data starting with with the path // dir. //