Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Lift'n'shift of existing code
Browse files Browse the repository at this point in the history
Factor out code to get a set of FolderEntries based on some path
information. This code will be used in BackupOp when merging item
details.
  • Loading branch information
ashmrtn committed Dec 22, 2022
1 parent aacb013 commit e91657b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
20 changes: 1 addition & 19 deletions src/internal/kopia/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,7 @@ func (cp *corsoProgress) FinishedFile(relativePath string, err error) {
d.info,
)

folders := []details.FolderEntry{}

for len(parent.Elements()) > 0 {
nextParent := parent.Dir()

folders = append(folders, details.FolderEntry{
RepoRef: parent.String(),
ShortRef: parent.ShortRef(),
ParentRef: nextParent.ShortRef(),
Info: details.ItemInfo{
Folder: &details.FolderInfo{
DisplayName: parent.Elements()[len(parent.Elements())-1],
},
},
})

parent = nextParent
}

folders := details.FolderEntriesForPath(parent)
cp.deets.AddFoldersForItem(folders, d.info)
}

Expand Down
26 changes: 26 additions & 0 deletions src/pkg/backup/details/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ func (b *Builder) Details() *Details {
return &b.d
}

// TODO(ashmrtn): If we never need to pre-populate the modified time of a folder
// we should just merge this with AddFoldersForItem, have Add call
// AddFoldersForItem, and unexport AddFoldersForItem.
func FolderEntriesForPath(parent *path.Builder) []FolderEntry {
folders := []FolderEntry{}

for len(parent.Elements()) > 0 {
nextParent := parent.Dir()

folders = append(folders, FolderEntry{
RepoRef: parent.String(),
ShortRef: parent.ShortRef(),
ParentRef: nextParent.ShortRef(),
Info: ItemInfo{
Folder: &FolderInfo{
DisplayName: parent.Elements()[len(parent.Elements())-1],
},
},
})

parent = nextParent
}

return folders
}

// AddFoldersForItem adds entries for the given folders. It skips adding entries that
// have been added by previous calls.
func (b *Builder) AddFoldersForItem(folders []FolderEntry, itemInfo ItemInfo) {
Expand Down

0 comments on commit e91657b

Please sign in to comment.