Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FileStore): CreateTemp accepts pattern used for file name #584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions filestore/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ func (fs fileStore) Delete(p Path) error {
return os.Remove(full)
}

func (fs fileStore) CreateTemp() (File, error) {
f, err := ioutil.TempFile(fs.base, "fstmp")
func (fs fileStore) CreateTemp(pattern string) (File, error) {
if pattern == "" {
pattern = "fstmp"
} else {
pattern = fmt.Sprintf("fstmp_%s", pattern)
}
f, err := ioutil.TempFile(fs.base, pattern)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion filestore/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ func Test_CreateFile(t *testing.T) {
func Test_CreateTempFile(t *testing.T) {
store, err := NewLocalFileStore(baseDir)
require.NoError(t, err)
file, err := store.CreateTemp()
file, err := store.CreateTemp("pattern")
require.NoError(t, err)
require.Contains(t, file.Path(), "fstmp_pattern")
defer func() {
err := store.Delete(file.Path())
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion filestore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ type FileStore interface {
Store(p Path, f File) (Path, error)
Delete(p Path) error

CreateTemp() (File, error)
CreateTemp(pattern string) (File, error)
}
2 changes: 1 addition & 1 deletion shared_testutil/test_filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (fs *TestFileStore) Delete(p filestore.Path) error {
}

// CreateTemp will create a temporary file from the provided set of temporary files
func (fs *TestFileStore) CreateTemp() (filestore.File, error) {
func (fs *TestFileStore) CreateTemp(pattern string) (filestore.File, error) {
if len(fs.availableTempFiles) == 0 {
return nil, TestErrTempFile
}
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (p *Provider) ImportDataForDeal(ctx context.Context, propCid cid.Cid, data
return xerrors.Errorf("failed getting deal %s: %w", propCid, err)
}

tempfi, err := p.fs.CreateTemp()
tempfi, err := p.fs.CreateTemp(propCid.String())
if err != nil {
return xerrors.Errorf("failed to create temp file for data import: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/providerutils/providerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func GeneratePieceCommitmentWithMetadata(
payloadCid cid.Cid,
selector ipld.Node,
storeID *multistore.StoreID) (cid.Cid, abi.UnpaddedPieceSize, filestore.Path, error) {
metadataFile, err := fileStore.CreateTemp()
metadataFile, err := fileStore.CreateTemp(payloadCid.String())
if err != nil {
return cid.Cid{}, 0, "", err
}
Expand Down