diff --git a/pkg/storage/filestorage.go b/pkg/storage/filestorage.go index f26ecfb..9d62f34 100644 --- a/pkg/storage/filestorage.go +++ b/pkg/storage/filestorage.go @@ -29,10 +29,6 @@ func (s *FileStorageInteractor) CatFileFromStorage(name string, offset int64, _ _, err = io.CopyN(io.Discard, file, offset) return file, err } -func LastFiveDirsInPath(path string) string { - p1 := strings.Split(path, "/") - return fmt.Sprintf("/%s/%s/%s/%s/%s", p1[len(p1)-5], p1[len(p1)-4], p1[len(p1)-3], p1[len(p1)-2], p1[len(p1)-1]) -} func (s *FileStorageInteractor) ListPath(prefix string) ([]*object.ObjectInfo, error) { var data []*object.ObjectInfo err := filepath.WalkDir(s.cnf.StoragePrefix+prefix, func(path string, d fs.DirEntry, err error) error { @@ -50,7 +46,11 @@ func (s *FileStorageInteractor) ListPath(prefix string) ([]*object.ObjectInfo, e if err != nil { return err } - data = append(data, &object.ObjectInfo{Path: LastFiveDirsInPath(path), Size: fileinfo.Size()}) + cPath, ok := strings.CutPrefix(path, prefix) + if !ok { + return err + } + data = append(data, &object.ObjectInfo{Path: cPath, Size: fileinfo.Size()}) return nil }) return data, err