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

Lift'n'shift of existing code #1925

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/internal/kopia/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,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