-
Notifications
You must be signed in to change notification settings - Fork 28
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
parses metadata collections using previous paths #4947
Changes from 2 commits
85ad56b
e326d82
3a54aaf
8028733
bc09410
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,7 @@ func CollectLists( | |
su support.StatusUpdater, | ||
counter *count.Bus, | ||
errs *fault.Bus, | ||
) ([]data.BackupCollection, error) { | ||
) ([]data.BackupCollection, bool, error) { | ||
logger.Ctx(ctx).Debug("Creating SharePoint List Collections") | ||
|
||
var ( | ||
|
@@ -160,9 +160,19 @@ func CollectLists( | |
currPaths = map[string]string{} | ||
) | ||
|
||
dps, canUsePreviousBackup, err := parseMetadataCollections(ctx, path.ListsCategory, bpc.MetadataCollections) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
|
||
// [TODO] utilise deltapaths to determine list's state | ||
_ = dps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: You could do this in line 163 itself i.e. |
||
|
||
ctx = clues.Add(ctx, "can_use_previous_backup", canUsePreviousBackup) | ||
|
||
lists, err := bh.GetItems(ctx, acc) | ||
if err != nil { | ||
return nil, err | ||
return nil, false, err | ||
} | ||
|
||
for _, list := range lists { | ||
|
@@ -204,7 +214,7 @@ func CollectLists( | |
path.ListsCategory, | ||
false) | ||
if err != nil { | ||
return nil, clues.WrapWC(ctx, err, "making metadata path prefix"). | ||
return nil, false, clues.WrapWC(ctx, err, "making metadata path prefix"). | ||
Label(count.BadPathPrefix) | ||
} | ||
|
||
|
@@ -216,12 +226,12 @@ func CollectLists( | |
su, | ||
counter.Local()) | ||
if err != nil { | ||
return nil, clues.WrapWC(ctx, err, "making metadata collection") | ||
return nil, false, clues.WrapWC(ctx, err, "making metadata collection") | ||
} | ||
|
||
spcs = append(spcs, col) | ||
|
||
return spcs, el.Failure() | ||
return spcs, canUsePreviousBackup, el.Failure() | ||
} | ||
|
||
func idAnd(ss ...string) []string { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package site | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/alcionai/clues" | ||
|
||
"github.com/alcionai/corso/src/internal/data" | ||
"github.com/alcionai/corso/src/pkg/backup/metadata" | ||
"github.com/alcionai/corso/src/pkg/fault" | ||
"github.com/alcionai/corso/src/pkg/logger" | ||
"github.com/alcionai/corso/src/pkg/path" | ||
) | ||
|
||
func parseMetadataCollections( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ctx context.Context, | ||
cat path.CategoryType, | ||
colls []data.RestoreCollection, | ||
) (metadata.DeltaPaths, bool, error) { | ||
cdp := metadata.CatDeltaPaths{ | ||
cat: {}, | ||
} | ||
|
||
found := map[path.CategoryType]map[string]struct{}{ | ||
cat: {}, | ||
} | ||
|
||
errs := fault.New(true) | ||
|
||
for _, coll := range colls { | ||
var ( | ||
breakLoop bool | ||
items = coll.Items(ctx, errs) | ||
category = coll.FullPath().Category() | ||
) | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return nil, false, clues.WrapWC(ctx, ctx.Err(), "parsing collection metadata") | ||
|
||
case item, ok := <-items: | ||
if !ok || errs.Failure() != nil { | ||
breakLoop = true | ||
break | ||
} | ||
|
||
var ( | ||
m = map[string]string{} | ||
cdps, wantedCategory = cdp[category] | ||
) | ||
|
||
if !wantedCategory { | ||
continue | ||
} | ||
|
||
err := json.NewDecoder(item.ToReader()).Decode(&m) | ||
if err != nil { | ||
return nil, false, clues.NewWC(ctx, "decoding metadata json") | ||
} | ||
|
||
if item.ID() == metadata.PreviousPathFileName { | ||
if _, ok := found[category][metadata.PathKey]; ok { | ||
return nil, false, clues.Wrap(clues.NewWC(ctx, category.String()), "multiple versions of path metadata") | ||
} | ||
|
||
for k, p := range m { | ||
cdps.AddPath(k, p) | ||
} | ||
|
||
found[category][metadata.PathKey] = struct{}{} | ||
|
||
cdp[category] = cdps | ||
} | ||
} | ||
|
||
if breakLoop { | ||
break | ||
} | ||
} | ||
} | ||
|
||
if errs.Failure() != nil { | ||
logger.CtxErr(ctx, errs.Failure()).Info("reading metadata collection items") | ||
|
||
return metadata.DeltaPaths{}, false, nil | ||
} | ||
|
||
for _, dps := range cdp { | ||
for k, dp := range dps { | ||
if len(dp.Path) == 0 { | ||
delete(dps, k) | ||
} | ||
} | ||
} | ||
|
||
return cdp[cat], true, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We use
// TODO(hiteshrepo): comment
as a convention for marking todos in code.