snapshotfs: expose functions to round-trip between fs.Entry and DirEntry

This commit is contained in:
Jarek Kowalski
2020-01-01 12:50:39 -08:00
parent 503fa74be5
commit 8ff8ec0a36
3 changed files with 11 additions and 6 deletions

View File

@@ -62,6 +62,10 @@ func (e *repositoryEntry) Owner() fs.OwnerInfo {
}
}
func (e *repositoryEntry) DirEntry() *snapshot.DirEntry {
return e.metadata
}
type repositoryDirectory struct {
repositoryEntry
summary *fs.DirectorySummary
@@ -97,7 +101,7 @@ func (rd *repositoryDirectory) Readdir(ctx context.Context) (fs.Entries, error)
entries := make(fs.Entries, len(metadata))
for i, m := range metadata {
entries[i], err = newRepoEntry(rd.repo, m)
entries[i], err = EntryFromDirEntry(rd.repo, m)
if err != nil {
return nil, errors.Wrapf(err, "error parsing entry %v", m)
}
@@ -133,7 +137,8 @@ func (rsl *repositorySymlink) Readlink(ctx context.Context) (string, error) {
return string(b), nil
}
func newRepoEntry(r *repo.Repository, md *snapshot.DirEntry) (fs.Entry, error) {
// EntryFromDirEntry returns a filesystem entry based on the directory entry.
func EntryFromDirEntry(r *repo.Repository, md *snapshot.DirEntry) (fs.Entry, error) {
re := repositoryEntry{
metadata: md,
repo: r,
@@ -175,7 +180,7 @@ func withFileInfo(r object.Reader, e fs.Entry) fs.Reader {
// DirectoryEntry returns fs.Directory based on repository object with the specified ID.
// The existence or validity of the directory object is not validated until its contents are read.
func DirectoryEntry(rep *repo.Repository, objectID object.ID, dirSummary *fs.DirectorySummary) fs.Directory {
d, _ := newRepoEntry(rep, &snapshot.DirEntry{
d, _ := EntryFromDirEntry(rep, &snapshot.DirEntry{
Name: "/",
Permissions: 0555,
Type: snapshot.EntryTypeDirectory,
@@ -193,7 +198,7 @@ func SnapshotRoot(rep *repo.Repository, man *snapshot.Manifest) (fs.Entry, error
return nil, errors.New("manifest root object ID")
}
return newRepoEntry(rep, man.RootEntry)
return EntryFromDirEntry(rep, man.RootEntry)
}
var _ fs.Directory = &repositoryDirectory{}

View File

@@ -86,7 +86,7 @@ func (s *sourceSnapshots) Readdir(ctx context.Context) (fs.Entries, error) {
de.DirSummary = m.RootEntry.DirSummary
}
e, err := newRepoEntry(s.rep, de)
e, err := EntryFromDirEntry(s.rep, de)
if err != nil {
return nil, errors.Wrap(err, "unable to create entry")
}

View File

@@ -702,7 +702,7 @@ func (u *Uploader) maybeOpenDirectoryFromManifest(man *snapshot.Manifest) fs.Dir
return nil
}
ent, err := newRepoEntry(u.repo, man.RootEntry)
ent, err := EntryFromDirEntry(u.repo, man.RootEntry)
if err != nil {
log.Warningf("invalid previous manifest root entry %v: %v", man.RootEntry, err)
return nil