forked from TrueCloudLab/rclone
[#9] refactor access to the CID cache
Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
This commit is contained in:
parent
12b572e62a
commit
c719874fd9
1 changed files with 12 additions and 15 deletions
|
@ -572,14 +572,15 @@ func (f *Fs) resolveOrCreateContainer(ctx context.Context, rootDirName string) (
|
||||||
f.m.Lock()
|
f.m.Lock()
|
||||||
defer f.m.Unlock()
|
defer f.m.Unlock()
|
||||||
|
|
||||||
cnrID, err := f.resolveContainerIDHelper(ctx, rootDirName)
|
cnrIDStr, ok := f.containerIDCache[rootDirName]
|
||||||
if err == nil {
|
if ok {
|
||||||
return cnrID, err
|
return parseContainerID(cnrIDStr)
|
||||||
}
|
}
|
||||||
|
cnrID, err := f.resolveCIDByRootDirName(ctx, rootDirName)
|
||||||
if cnrID, err = f.createContainer(ctx, rootDirName); err != nil {
|
if err != nil {
|
||||||
delete(f.containerIDCache, rootDirName)
|
if cnrID, err = f.createContainer(ctx, rootDirName); err != nil {
|
||||||
return cid.ID{}, fmt.Errorf("createContainer: %w", err)
|
return cid.ID{}, fmt.Errorf("createContainer: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
f.containerIDCache[rootDirName] = cnrID.String()
|
f.containerIDCache[rootDirName] = cnrID.String()
|
||||||
|
|
||||||
|
@ -1004,7 +1005,10 @@ func (f *Fs) resolveCIDByRootDirName(ctx context.Context, rootDirName string) (c
|
||||||
return cid.ID{}, fmt.Errorf("couldn't resolve container '%s'", rootDirName)
|
return cid.ID{}, fmt.Errorf("couldn't resolve container '%s'", rootDirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) resolveContainerIDHelper(ctx context.Context, rootDirName string) (cid.ID, error) {
|
func (f *Fs) resolveContainerID(ctx context.Context, rootDirName string) (cid.ID, error) {
|
||||||
|
f.m.Lock()
|
||||||
|
defer f.m.Unlock()
|
||||||
|
|
||||||
cnrIDStr, ok := f.containerIDCache[rootDirName]
|
cnrIDStr, ok := f.containerIDCache[rootDirName]
|
||||||
if ok {
|
if ok {
|
||||||
return parseContainerID(cnrIDStr)
|
return parseContainerID(cnrIDStr)
|
||||||
|
@ -1017,13 +1021,6 @@ func (f *Fs) resolveContainerIDHelper(ctx context.Context, rootDirName string) (
|
||||||
return cnrID, nil
|
return cnrID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) resolveContainerID(ctx context.Context, rootDirName string) (cid.ID, error) {
|
|
||||||
f.m.Lock()
|
|
||||||
defer f.m.Unlock()
|
|
||||||
|
|
||||||
return f.resolveContainerIDHelper(ctx, rootDirName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Fs) parseContainer(ctx context.Context, rootDirName string) (cid.ID, error) {
|
func (f *Fs) parseContainer(ctx context.Context, rootDirName string) (cid.ID, error) {
|
||||||
cnrID, err := parseContainerID(rootDirName)
|
cnrID, err := parseContainerID(rootDirName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue