Skip to content

Commit

Permalink
Fix the ObjectExists method on FSObjectClient
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hollands <[email protected]>
  • Loading branch information
MichelHollands committed Jan 23, 2024
1 parent de251c3 commit 7b32e70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/storage/chunk/client/local/fs_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func NewFSObjectClient(cfg FSConfig) (*FSObjectClient, error) {
func (FSObjectClient) Stop() {}

func (f *FSObjectClient) ObjectExists(_ context.Context, objectKey string) (bool, error) {
_, err := os.Lstat(objectKey)
fullPath := filepath.Join(f.cfg.Directory, filepath.FromSlash(objectKey))
_, err := os.Lstat(fullPath)
if err != nil {
return false, err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/storage/chunk/client/local/fs_object_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestFSObjectClient_DeleteChunksBefore(t *testing.T) {
require.Equal(t, 1, len(files), "Number of files should be 1 after enforcing retention")
}

func TestFSObjectClient_List(t *testing.T) {
func TestFSObjectClient_List_and_ObjectExists(t *testing.T) {
fsObjectsDir := t.TempDir()

bucketClient, err := NewFSObjectClient(FSConfig{
Expand Down Expand Up @@ -152,6 +152,10 @@ func TestFSObjectClient_List(t *testing.T) {
require.Len(t, storageObjects, 1)
require.Equal(t, "outer-file1", storageObjects[0].Key)
require.Empty(t, commonPrefixes)

ok, err := bucketClient.ObjectExists(context.Background(), "outer-file2")
require.NoError(t, err)
require.True(t, ok)
}

func TestFSObjectClient_DeleteObject(t *testing.T) {
Expand Down

0 comments on commit 7b32e70

Please sign in to comment.