Skip to content

Commit cb9c518

Browse files
committed
always use absolute path in LocalStorage
1 parent 32dfaa7 commit cb9c518

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

modules/storage/local.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package storage
55

66
import (
77
"context"
8+
"fmt"
89
"io"
910
"net/url"
1011
"os"
@@ -40,13 +41,19 @@ func NewLocalStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
4041
}
4142
config := configInterface.(LocalStorageConfig)
4243

44+
if !filepath.IsAbs(config.Path) {
45+
return nil, fmt.Errorf("LocalStorageConfig.Path should have been prepared by setting/storage.go and should be an absolute path, but not: %q", config.Path)
46+
}
4347
log.Info("Creating new Local Storage at %s", config.Path)
4448
if err := os.MkdirAll(config.Path, os.ModePerm); err != nil {
4549
return nil, err
4650
}
4751

4852
if config.TemporaryPath == "" {
49-
config.TemporaryPath = config.Path + "/tmp"
53+
config.TemporaryPath = filepath.Join(config.Path, "tmp")
54+
}
55+
if !filepath.IsAbs(config.TemporaryPath) {
56+
return nil, fmt.Errorf("LocalStorageConfig.TemporaryPath should be an absolute path, but not: %q", config.TemporaryPath)
5057
}
5158

5259
return &LocalStorage{

modules/storage/local_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@ func TestBuildLocalPath(t *testing.T) {
2020
expected string
2121
}{
2222
{
23-
"a",
23+
"/a",
2424
"0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
25-
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
25+
"/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
2626
},
2727
{
28-
"a",
28+
"/a",
2929
"../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
30-
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
30+
"/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
3131
},
3232
{
33-
"a",
33+
"/a",
3434
"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
35-
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
35+
"/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
3636
},
3737
{
38-
"b",
38+
"/b",
3939
"a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
40-
"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
40+
"/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
4141
},
4242
{
43-
"b",
43+
"/b",
4444
"a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
45-
"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
45+
"/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
4646
},
4747
}
4848

0 commit comments

Comments
 (0)