Skip to content

Commit

Permalink
Fix localfs prefix (#106)
Browse files Browse the repository at this point in the history
* fix localfs prefix
* fix test to ignore already closed
  • Loading branch information
junichif authored Apr 23, 2024
1 parent 94a4634 commit 4b211b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 9 additions & 2 deletions localfs/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,16 @@ func (l *LocalStore) NewObject(objectname string) (cloudstorage.Object, error) {

// List objects at Query location.
func (l *LocalStore) List(ctx context.Context, query cloudstorage.Query) (*cloudstorage.ObjectsResponse, error) {

resp := cloudstorage.NewObjectsResponse()
objects := make(map[string]*object)
metadatas := make(map[string]map[string]string)

spath := path.Join(l.storepath, query.Prefix)
spath := l.storepath
filePre := query.Prefix
li := strings.LastIndex(query.Prefix, "/")
if li > 0 {
spath = path.Join(spath, query.Prefix[:li])
}
if !cloudstorage.Exists(spath) {
return resp, nil
}
Expand All @@ -153,6 +157,9 @@ func (l *LocalStore) List(ctx context.Context, query cloudstorage.Query) (*cloud
metadatas[mdkey] = metadata
} else {
oname := strings.TrimPrefix(obj, "/")
if filePre != "" && !strings.HasPrefix(oname, filePre) {
return nil
}

if (query.StartOffset != "" && oname < query.StartOffset) ||
(query.EndOffset != "" && oname >= query.EndOffset) {
Expand Down
6 changes: 2 additions & 4 deletions testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ func BasicRW(t *testing.T, store cloudstorage.Store) {

f2, err := obj2.Open(cloudstorage.ReadOnly)
defer func() {
err := f2.Close()
if err != nil {
t.Errorf("error closing file: %v", err)
}
// Delete should close the file
_ = f2.Close()
}()
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%p", f2), fmt.Sprintf("%p", obj2.File()))
Expand Down

0 comments on commit 4b211b8

Please sign in to comment.