Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Fix use of path where filepath is needed #210

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions blob/local_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"io"
"os"
"path"
"path/filepath"
)

var _ Store = (*LocalStore)(nil)
Expand Down Expand Up @@ -51,7 +51,7 @@ func (l *LocalStore) Put(_ context.Context, reader io.ReadCloser) (*Descriptor,
os.Remove(dest.Name())
return nil, err
}
if err = os.Rename(dest.Name(), path.Join(l.dir, id.String()+".bin")); err != nil {
if err = os.Rename(dest.Name(), filepath.Join(l.dir, id.String()+".bin")); err != nil {
return nil, err
}
stat, err := dest.Stat()
Expand All @@ -68,29 +68,29 @@ func (l *LocalStore) Put(_ context.Context, reader io.ReadCloser) (*Descriptor,
// Get Retrieves the content of blob.
// If no blob is found for the given id, ErrBlobNotFound is returned.
func (l *LocalStore) Get(_ context.Context, id ID) (io.ReadSeekCloser, error) {
switch blob, err := os.Open(path.Join(l.dir, id.String()+".bin")); {
case err == nil:
return blob, nil
case errors.Is(err, os.ErrNotExist):
return nil, ErrBlobNotFound
default:
blob, err := os.Open(filepath.Join(l.dir, id.String()+".bin"))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrBlobNotFound
}
return nil, err
}
return blob, nil
}

// Describe gets the description of the blob for the given id.
// If no blob is found for the given id, ErrBlobNotFound is returned.
func (l *LocalStore) Describe(ctx context.Context, id ID) (*Descriptor, error) {
switch stat, err := os.Stat(path.Join(l.dir, id.String()+".bin")); {
case err == nil:
return &Descriptor{
ID: id,
Size: uint64(stat.Size()),
ModificationTime: stat.ModTime(),
}, nil
case errors.Is(err, os.ErrNotExist):
return nil, ErrBlobNotFound
default:
stat, err := os.Stat(filepath.Join(l.dir, id.String()+".bin"))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrBlobNotFound
}
return nil, err
}
return &Descriptor{
ID: id,
Size: uint64(stat.Size()),
ModificationTime: stat.ModTime(),
}, nil
}
33 changes: 18 additions & 15 deletions integration/ribs/ribs_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"time"

"github.com/filecoin-project/lotus/chain/types"
Expand Down Expand Up @@ -56,12 +56,12 @@ type (

// NewRibsStore instantiates a new experimental RIBS store.
func NewRibsStore(dir string, ks types.KeyStore) (*RibsStore, error) {
dir = path.Clean(dir)
rbdealDir := path.Join(dir, "rbdeal")
dir = filepath.Clean(dir)
rbdealDir := filepath.Join(dir, "rbdeal")
if err := os.Mkdir(rbdealDir, 0750); err != nil && !errors.Is(err, os.ErrExist) {
return nil, fmt.Errorf("failed to create RIBS deal directory: %w", err)
}
indexDir := path.Join(dir, "index")
indexDir := filepath.Join(dir, "index")
if err := os.Mkdir(indexDir, 0750); err != nil && !errors.Is(err, os.ErrExist) {
return nil, fmt.Errorf("failed to create RIBS internal directory: %w", err)
}
Expand Down Expand Up @@ -144,11 +144,12 @@ SplitLoop:
},
Chunks: chunkCids,
}
index, err := os.Create(path.Join(r.indexDir, id.String()))
index, err := os.Create(filepath.Join(r.indexDir, id.String()))
if err != nil {
return nil, err
}
if err := json.NewEncoder(index).Encode(storedBlob); err != nil {
defer index.Close()
if err = json.NewEncoder(index).Encode(storedBlob); err != nil {
return nil, err
}
return storedBlob.Descriptor, nil
Expand Down Expand Up @@ -176,17 +177,19 @@ func (r *RibsStore) Describe(ctx context.Context, id blob.ID) (*blob.Descriptor,
}

func (r *RibsStore) describeRibsStoredBlob(_ context.Context, id blob.ID) (*ribsStoredBlob, error) {
switch index, err := os.Open(path.Join(r.indexDir, id.String())); {
case err == nil:
var storedBlob ribsStoredBlob
err := json.NewDecoder(index).Decode(&storedBlob)
// TODO: populate descriptor status with Filecoin chain data about the stored blob.
return &storedBlob, err
case errors.Is(err, os.ErrNotExist):
return nil, blob.ErrBlobNotFound
default:
index, err := os.Open(filepath.Join(r.indexDir, id.String()))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, blob.ErrBlobNotFound
}
return nil, err
}
defer index.Close()

var storedBlob ribsStoredBlob
err = json.NewDecoder(index).Decode(&storedBlob)
// TODO: populate descriptor status with Filecoin chain data about the stored blob.
return &storedBlob, err
}

func (r *RibsStore) Shutdown(_ context.Context) error {
Expand Down