Skip to content

Commit

Permalink
Go add pack multi-level files
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Sep 7, 2024
1 parent dfd6ca7 commit ee80867
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
24 changes: 19 additions & 5 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,28 @@ func parseDirFilelist(repo *repomgr.Repo, obj map[string]interface{}) ([]fsmgr.S
err := fmt.Errorf("invalid download multi data")
return nil, err
}

v, ok := direntHash[name]
if !ok {
err := fmt.Errorf("invalid download multi data")
if name == "" {
err := fmt.Errorf("invalid download file name")
return nil, err
}

direntList = append(direntList, v)
if strings.Contains(name, "/") {
rpath := filepath.Join(parentDir, name)
dent, err := fsmgr.GetDirentByPath(repo.StoreID, repo.RootID, rpath)
if err != nil {
err := fmt.Errorf("failed to get path %s for repo %s: %v", rpath, repo.StoreID, err)
return nil, err
}
direntList = append(direntList, *dent)
} else {
v, ok := direntHash[name]
if !ok {
err := fmt.Errorf("invalid download multi data")
return nil, err
}

direntList = append(direntList, v)
}
}

return direntList, nil
Expand Down
28 changes: 28 additions & 0 deletions fileserver/fsmgr/fsmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,3 +908,31 @@ func getFileCountInfo(repoID, dirID string) (*FileCountInfo, error) {

return info, nil
}

func GetDirentByPath(repoID, rootID, rpath string) (*SeafDirent, error) {
parentDir := filepath.Dir(rpath)
fileName := filepath.Base(rpath)

var dir *SeafDir
var err error

if parentDir == "." {
dir, err = GetSeafdir(repoID, rootID)
if err != nil {
return nil, err
}
} else {
dir, err = GetSeafdirByPath(repoID, rootID, parentDir)
if err != nil {
return nil, err
}
}

for _, de := range dir.Entries {
if de.Name == fileName {
return de, nil
}
}

return nil, fmt.Errorf("failed to get dirent %s", rpath)
}

0 comments on commit ee80867

Please sign in to comment.