Skip to content

Commit

Permalink
fix for handling paths correctly (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolina79 authored Jun 8, 2020
1 parent cbfe6ec commit ae7163a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/space/services/services_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ func (s *Space) OpenFile(ctx context.Context, path string, bucketSlug string) (d

// write file copy to temp folder
cfg := s.GetConfig(ctx)
_, fileName := filepath.Split(path)
// NOTE: the pattern of the file ensures that it retains extension. e.g (rand num) + filename/path
tmpFile, err := ioutil.TempFile(cfg.FolderPath, "*-"+path)
tmpFile, err := ioutil.TempFile(cfg.FolderPath, "*-"+fileName)
if err != nil {
log.Error("cannot create temp file while executing OpenFile", err)
return domain.OpenFileInfo{}, err
Expand Down
5 changes: 3 additions & 2 deletions core/space/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ func TestService_OpenFile(t *testing.T) {
defer tearDown()

testKey := "bucketKey"
testPath := "test.txt"
testPath := "/ipfs/bafybeievdakous3kamdgy6yxtmkvmibmro23kgf7xrduvwrxrlryzvu3sm/file.txt"
testFileName := "file.txt"

// setup mocks
cfg.On("GetString", config.SpaceFolderPath, "").Return(
Expand Down Expand Up @@ -233,7 +234,7 @@ func TestService_OpenFile(t *testing.T) {
assert.NotEmpty(t, res)
assert.FileExists(t, res.Location)
assert.Contains(t, res.Location, getDir().dir)
assert.True(t, strings.HasSuffix(res.Location, testPath))
assert.True(t, strings.HasSuffix(res.Location, testFileName))
// assert mocks
cfg.AssertExpectations(t)
textileClient.AssertExpectations(t)
Expand Down

0 comments on commit ae7163a

Please sign in to comment.