From 641f07cecf21fc5636bac529500a93669d3605bc Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Jun 2015 16:02:34 -0700 Subject: [PATCH] Use filepath everywhere instead of path.{} functions for portability - fixes #656 --- commands.go | 4 +- pkg/api/config/config.go | 6 +-- pkg/api/config/config_test.go | 4 +- pkg/api/web/web.go | 4 +- pkg/iodine/iodine.go | 12 +++--- pkg/storage/donut/donut_bucket.go | 6 +-- pkg/storage/donut/donut_bucket_internal.go | 6 +-- pkg/storage/donut/donut_disk_darwin.go | 14 +++---- pkg/storage/donut/donut_disk_linux.go | 14 +++---- pkg/storage/donut/donut_object.go | 11 +++-- pkg/storage/donut/donut_test.go | 4 +- pkg/storage/donut/management.go | 4 +- pkg/storage/donut/objectstorage_internal.go | 8 ++-- pkg/storage/drivers/donut/donut.go | 6 +-- pkg/storage/drivers/fs/fs_bucket.go | 9 ++-- pkg/storage/drivers/fs/fs_multipart.go | 46 ++++++++++++++------- pkg/storage/drivers/fs/fs_object.go | 16 +++---- 17 files changed, 94 insertions(+), 80 deletions(-) diff --git a/commands.go b/commands.go index da7062736..22c0d1158 100644 --- a/commands.go +++ b/commands.go @@ -2,7 +2,7 @@ package main import ( "os/user" - "path" + "path/filepath" "strings" "time" @@ -164,7 +164,7 @@ func runDonut(c *cli.Context) { // supporting multiple paths var paths []string if strings.TrimSpace(c.Args().First()) == "" { - p := path.Join(u.HomeDir, "minio-storage", "donut") + p := filepath.Join(u.HomeDir, "minio-storage", "donut") paths = append(paths, p) } else { for _, arg := range c.Args() { diff --git a/pkg/api/config/config.go b/pkg/api/config/config.go index 9aa27b894..96f9e9efe 100644 --- a/pkg/api/config/config.go +++ b/pkg/api/config/config.go @@ -21,7 +21,7 @@ import ( "io" "os" "os/user" - "path" + "path/filepath" "sync" "github.com/minio/minio/pkg/iodine" @@ -49,13 +49,13 @@ func (c *Config) SetupConfig() error { return iodine.New(err, nil) } - confPath := path.Join(u.HomeDir, ".minio") + confPath := filepath.Join(u.HomeDir, ".minio") if err := os.MkdirAll(confPath, 0700); err != nil { return iodine.New(err, nil) } c.ConfigPath = confPath - c.ConfigFile = path.Join(c.ConfigPath, "config.json") + c.ConfigFile = filepath.Join(c.ConfigPath, "config.json") if _, err := os.Stat(c.ConfigFile); os.IsNotExist(err) { _, err = os.Create(c.ConfigFile) if err != nil { diff --git a/pkg/api/config/config_test.go b/pkg/api/config/config_test.go index 4126fea21..f2ca5bd2e 100644 --- a/pkg/api/config/config_test.go +++ b/pkg/api/config/config_test.go @@ -19,7 +19,7 @@ package config import ( "io/ioutil" "os" - "path" + "path/filepath" "sync" "testing" @@ -38,7 +38,7 @@ func (s *MySuite) TestConfig(c *C) { conf.ConfigLock = new(sync.RWMutex) conf.ConfigPath, _ = ioutil.TempDir("/tmp", "minio-test-") defer os.RemoveAll(conf.ConfigPath) - conf.ConfigFile = path.Join(conf.ConfigPath, "config.json") + conf.ConfigFile = filepath.Join(conf.ConfigPath, "config.json") if _, err := os.Stat(conf.ConfigFile); os.IsNotExist(err) { _, err = os.Create(conf.ConfigFile) if err != nil { diff --git a/pkg/api/web/web.go b/pkg/api/web/web.go index 7efafe3bc..4e7ffeae9 100644 --- a/pkg/api/web/web.go +++ b/pkg/api/web/web.go @@ -20,7 +20,7 @@ import ( "bytes" "encoding/json" "net/http" - "path" + "path/filepath" "github.com/gorilla/mux" "github.com/minio/minio/pkg/api/config" @@ -52,7 +52,7 @@ func HTTPHandler() http.Handler { log.Fatal(iodine.New(err, nil)) } - api.webPath = path.Join(api.conf.GetConfigPath(), defaultWeb) + api.webPath = filepath.Join(api.conf.GetConfigPath(), defaultWeb) mux.Handle("/{polygon:.*}", http.FileServer(http.Dir(api.webPath))).Methods("GET") mux.HandleFunc("/access", api.accessHandler).Methods("POST") return mux diff --git a/pkg/iodine/iodine.go b/pkg/iodine/iodine.go index 481a79339..b297c7170 100644 --- a/pkg/iodine/iodine.go +++ b/pkg/iodine/iodine.go @@ -22,7 +22,7 @@ import ( "errors" "fmt" "os" - "path" + "path/filepath" "reflect" "runtime" "strconv" @@ -151,7 +151,7 @@ func createStackEntry() StackEntry { host, _ := os.Hostname() pc, file, line, _ := runtime.Caller(2) function := runtime.FuncForPC(pc).Name() - _, function = path.Split(function) + _, function = filepath.Split(function) file = strings.TrimPrefix(file, gopath) // trim gopath from file data := GetGlobalState() @@ -222,8 +222,8 @@ func (err Error) Error() string { func init() { _, iodineFile, _, _ := runtime.Caller(0) - iodineFile = path.Dir(iodineFile) // trim iodine.go - iodineFile = path.Dir(iodineFile) // trim iodine - iodineFile = path.Dir(iodineFile) // trim minio - gopath = path.Dir(iodineFile) + "/" // trim github.com + iodineFile = filepath.Dir(iodineFile) // trim iodine.go + iodineFile = filepath.Dir(iodineFile) // trim iodine + iodineFile = filepath.Dir(iodineFile) // trim minio + gopath = filepath.Dir(iodineFile) + "/" // trim github.com } diff --git a/pkg/storage/donut/donut_bucket.go b/pkg/storage/donut/donut_bucket.go index 185e0cef8..1eb87584c 100644 --- a/pkg/storage/donut/donut_bucket.go +++ b/pkg/storage/donut/donut_bucket.go @@ -21,7 +21,7 @@ import ( "fmt" "io" "os" - "path" + "path/filepath" "strconv" "strings" "time" @@ -76,13 +76,13 @@ func (b bucket) ListObjects() (map[string]Object, error) { } for _, disk := range disks { bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) - bucketPath := path.Join(b.donutName, bucketSlice) + bucketPath := filepath.Join(b.donutName, bucketSlice) objects, err := disk.ListDir(bucketPath) if err != nil { return nil, iodine.New(err, nil) } for _, object := range objects { - newObject, err := NewObject(object.Name(), path.Join(disk.GetPath(), bucketPath)) + newObject, err := NewObject(object.Name(), filepath.Join(disk.GetPath(), bucketPath)) if err != nil { return nil, iodine.New(err, nil) } diff --git a/pkg/storage/donut/donut_bucket_internal.go b/pkg/storage/donut/donut_bucket_internal.go index 5ab9d211e..8ddebbb2d 100644 --- a/pkg/storage/donut/donut_bucket_internal.go +++ b/pkg/storage/donut/donut_bucket_internal.go @@ -25,7 +25,7 @@ import ( "fmt" "hash" "io" - "path" + "path/filepath" "strconv" "strings" @@ -278,7 +278,7 @@ func (b bucket) getDiskReaders(objectName, objectMeta string) ([]io.ReadCloser, readers = make([]io.ReadCloser, len(disks)) for _, disk := range disks { bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) - objectPath := path.Join(b.donutName, bucketSlice, objectName, objectMeta) + objectPath := filepath.Join(b.donutName, bucketSlice, objectName, objectMeta) objectSlice, err := disk.OpenFile(objectPath) if err != nil { return nil, iodine.New(err, nil) @@ -302,7 +302,7 @@ func (b bucket) getDiskWriters(objectName, objectMeta string) ([]io.WriteCloser, writers = make([]io.WriteCloser, len(disks)) for _, disk := range disks { bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) - objectPath := path.Join(b.donutName, bucketSlice, objectName, objectMeta) + objectPath := filepath.Join(b.donutName, bucketSlice, objectName, objectMeta) objectSlice, err := disk.MakeFile(objectPath) if err != nil { return nil, iodine.New(err, nil) diff --git a/pkg/storage/donut/donut_disk_darwin.go b/pkg/storage/donut/donut_disk_darwin.go index e912ea167..b6eba7e91 100644 --- a/pkg/storage/donut/donut_disk_darwin.go +++ b/pkg/storage/donut/donut_disk_darwin.go @@ -19,7 +19,7 @@ package donut import ( "errors" "os" - "path" + "path/filepath" "syscall" "io/ioutil" @@ -88,12 +88,12 @@ func (d disk) GetFSInfo() map[string]string { // MakeDir - make a directory inside disk root path func (d disk) MakeDir(dirname string) error { - return os.MkdirAll(path.Join(d.root, dirname), 0700) + return os.MkdirAll(filepath.Join(d.root, dirname), 0700) } // ListDir - list a directory inside disk root path, get only directories func (d disk) ListDir(dirname string) ([]os.FileInfo, error) { - contents, err := ioutil.ReadDir(path.Join(d.root, dirname)) + contents, err := ioutil.ReadDir(filepath.Join(d.root, dirname)) if err != nil { return nil, iodine.New(err, nil) } @@ -109,7 +109,7 @@ func (d disk) ListDir(dirname string) ([]os.FileInfo, error) { // ListFiles - list a directory inside disk root path, get only files func (d disk) ListFiles(dirname string) ([]os.FileInfo, error) { - contents, err := ioutil.ReadDir(path.Join(d.root, dirname)) + contents, err := ioutil.ReadDir(filepath.Join(d.root, dirname)) if err != nil { return nil, iodine.New(err, nil) } @@ -128,9 +128,9 @@ func (d disk) MakeFile(filename string) (*os.File, error) { if filename == "" { return nil, iodine.New(errors.New("Invalid argument"), nil) } - filePath := path.Join(d.root, filename) + filePath := filepath.Join(d.root, filename) // Create directories if they don't exist - if err := os.MkdirAll(path.Dir(filePath), 0700); err != nil { + if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil { return nil, iodine.New(err, nil) } dataFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0600) @@ -145,7 +145,7 @@ func (d disk) OpenFile(filename string) (*os.File, error) { if filename == "" { return nil, iodine.New(errors.New("Invalid argument"), nil) } - dataFile, err := os.Open(path.Join(d.root, filename)) + dataFile, err := os.Open(filepath.Join(d.root, filename)) if err != nil { return nil, iodine.New(err, nil) } diff --git a/pkg/storage/donut/donut_disk_linux.go b/pkg/storage/donut/donut_disk_linux.go index da186896f..daa54840c 100644 --- a/pkg/storage/donut/donut_disk_linux.go +++ b/pkg/storage/donut/donut_disk_linux.go @@ -19,7 +19,7 @@ package donut import ( "errors" "os" - "path" + "path/filepath" "syscall" "io/ioutil" @@ -88,12 +88,12 @@ func (d disk) GetFSInfo() map[string]string { // MakeDir - make a directory inside disk root path func (d disk) MakeDir(dirname string) error { - return os.MkdirAll(path.Join(d.root, dirname), 0700) + return os.MkdirAll(filepath.Join(d.root, dirname), 0700) } // ListDir - list a directory inside disk root path, get only directories func (d disk) ListDir(dirname string) ([]os.FileInfo, error) { - contents, err := ioutil.ReadDir(path.Join(d.root, dirname)) + contents, err := ioutil.ReadDir(filepath.Join(d.root, dirname)) if err != nil { return nil, iodine.New(err, nil) } @@ -109,7 +109,7 @@ func (d disk) ListDir(dirname string) ([]os.FileInfo, error) { // ListFiles - list a directory inside disk root path, get only files func (d disk) ListFiles(dirname string) ([]os.FileInfo, error) { - contents, err := ioutil.ReadDir(path.Join(d.root, dirname)) + contents, err := ioutil.ReadDir(filepath.Join(d.root, dirname)) if err != nil { return nil, iodine.New(err, nil) } @@ -128,9 +128,9 @@ func (d disk) MakeFile(filename string) (*os.File, error) { if filename == "" { return nil, iodine.New(errors.New("Invalid argument"), nil) } - filePath := path.Join(d.root, filename) + filePath := filepath.Join(d.root, filename) // Create directories if they don't exist - if err := os.MkdirAll(path.Dir(filePath), 0700); err != nil { + if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil { return nil, iodine.New(err, nil) } dataFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0600) @@ -145,7 +145,7 @@ func (d disk) OpenFile(filename string) (*os.File, error) { if filename == "" { return nil, iodine.New(errors.New("Invalid argument"), nil) } - dataFile, err := os.Open(path.Join(d.root, filename)) + dataFile, err := os.Open(filepath.Join(d.root, filename)) if err != nil { return nil, iodine.New(err, nil) } diff --git a/pkg/storage/donut/donut_object.go b/pkg/storage/donut/donut_object.go index a392bbede..f0744af51 100644 --- a/pkg/storage/donut/donut_object.go +++ b/pkg/storage/donut/donut_object.go @@ -17,11 +17,10 @@ package donut import ( - "errors" - "path" - "encoding/json" + "errors" "io/ioutil" + "path/filepath" ) // object internal struct @@ -39,13 +38,13 @@ func NewObject(objectName, p string) (Object, error) { } o := object{} o.name = objectName - o.objectPath = path.Join(p, objectName) + o.objectPath = filepath.Join(p, objectName) return o, nil } func (o object) GetObjectMetadata() (map[string]string, error) { objectMetadata := make(map[string]string) - objectMetadataBytes, err := ioutil.ReadFile(path.Join(o.objectPath, objectMetadataConfig)) + objectMetadataBytes, err := ioutil.ReadFile(filepath.Join(o.objectPath, objectMetadataConfig)) if err != nil { return nil, err } @@ -58,7 +57,7 @@ func (o object) GetObjectMetadata() (map[string]string, error) { func (o object) GetDonutObjectMetadata() (map[string]string, error) { donutObjectMetadata := make(map[string]string) - donutObjectMetadataBytes, err := ioutil.ReadFile(path.Join(o.objectPath, donutObjectMetadataConfig)) + donutObjectMetadataBytes, err := ioutil.ReadFile(filepath.Join(o.objectPath, donutObjectMetadataConfig)) if err != nil { return nil, err } diff --git a/pkg/storage/donut/donut_test.go b/pkg/storage/donut/donut_test.go index 6277385f2..23b69769e 100644 --- a/pkg/storage/donut/donut_test.go +++ b/pkg/storage/donut/donut_test.go @@ -23,7 +23,7 @@ import ( "io" "io/ioutil" "os" - "path" + "path/filepath" "strconv" "testing" "time" @@ -42,7 +42,7 @@ func createTestNodeDiskMap(p string) map[string][]string { nodes := make(map[string][]string) nodes["localhost"] = make([]string, 16) for i := 0; i < len(nodes["localhost"]); i++ { - diskPath := path.Join(p, strconv.Itoa(i)) + diskPath := filepath.Join(p, strconv.Itoa(i)) if _, err := os.Stat(diskPath); err != nil { if os.IsNotExist(err) { os.MkdirAll(diskPath, 0700) diff --git a/pkg/storage/donut/management.go b/pkg/storage/donut/management.go index 2fc5a4e17..f2ed82722 100644 --- a/pkg/storage/donut/management.go +++ b/pkg/storage/donut/management.go @@ -3,7 +3,7 @@ package donut import ( "encoding/json" "errors" - "path" + "path/filepath" "github.com/minio/minio/pkg/iodine" ) @@ -54,7 +54,7 @@ func (d donut) SaveConfig() error { return iodine.New(err, nil) } for _, disk := range disks { - donutConfigPath := path.Join(d.name, donutConfig) + donutConfigPath := filepath.Join(d.name, donutConfig) donutConfigWriter, err := disk.MakeFile(donutConfigPath) defer donutConfigWriter.Close() if err != nil { diff --git a/pkg/storage/donut/objectstorage_internal.go b/pkg/storage/donut/objectstorage_internal.go index 73d190976..7e82f1196 100644 --- a/pkg/storage/donut/objectstorage_internal.go +++ b/pkg/storage/donut/objectstorage_internal.go @@ -22,7 +22,7 @@ import ( "fmt" "io" "os" - "path" + "path/filepath" "strings" "github.com/minio/minio/pkg/iodine" @@ -40,7 +40,7 @@ func (d donut) getBucketMetadataWriters() ([]io.WriteCloser, error) { } writers = make([]io.WriteCloser, len(disks)) for _, disk := range disks { - bucketMetaDataWriter, err := disk.MakeFile(path.Join(d.name, bucketMetadataConfig)) + bucketMetaDataWriter, err := disk.MakeFile(filepath.Join(d.name, bucketMetadataConfig)) if err != nil { return nil, iodine.New(err, nil) } @@ -59,7 +59,7 @@ func (d donut) getBucketMetadataReaders() ([]io.ReadCloser, error) { } readers = make([]io.ReadCloser, len(disks)) for _, disk := range disks { - bucketMetaDataReader, err := disk.OpenFile(path.Join(d.name, bucketMetadataConfig)) + bucketMetaDataReader, err := disk.OpenFile(filepath.Join(d.name, bucketMetadataConfig)) if err != nil { return nil, iodine.New(err, nil) } @@ -126,7 +126,7 @@ func (d donut) makeDonutBucket(bucketName, acl string) error { } for _, disk := range disks { bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, disk.GetOrder()) - err := disk.MakeDir(path.Join(d.name, bucketSlice)) + err := disk.MakeDir(filepath.Join(d.name, bucketSlice)) if err != nil { return iodine.New(err, nil) } diff --git a/pkg/storage/drivers/donut/donut.go b/pkg/storage/drivers/donut/donut.go index c64072e04..ccf23a45d 100644 --- a/pkg/storage/drivers/donut/donut.go +++ b/pkg/storage/drivers/donut/donut.go @@ -21,7 +21,7 @@ import ( "encoding/hex" "io" "os" - "path" + "path/filepath" "sort" "strconv" "strings" @@ -56,7 +56,7 @@ func createNodeDiskMap(p string) map[string][]string { nodes := make(map[string][]string) nodes["localhost"] = make([]string, 16) for i := 0; i < len(nodes["localhost"]); i++ { - diskPath := path.Join(p, strconv.Itoa(i)) + diskPath := filepath.Join(p, strconv.Itoa(i)) if _, err := os.Stat(diskPath); err != nil { if os.IsNotExist(err) { os.MkdirAll(diskPath, 0700) @@ -74,7 +74,7 @@ func createNodeDiskMapFromSlice(paths []string) map[string][]string { diskPaths := make([]string, len(paths)) nodes := make(map[string][]string) for i, p := range paths { - diskPath := path.Join(p, strconv.Itoa(i)) + diskPath := filepath.Join(p, strconv.Itoa(i)) if _, err := os.Stat(diskPath); err != nil { if os.IsNotExist(err) { os.MkdirAll(diskPath, 0700) diff --git a/pkg/storage/drivers/fs/fs_bucket.go b/pkg/storage/drivers/fs/fs_bucket.go index c57a9047c..6c871da85 100644 --- a/pkg/storage/drivers/fs/fs_bucket.go +++ b/pkg/storage/drivers/fs/fs_bucket.go @@ -18,7 +18,6 @@ package filesystem import ( "os" - "path" "sort" "io/ioutil" @@ -70,7 +69,7 @@ func (fs *fsDriver) CreateBucket(bucket, acl string) error { } // get bucket path - bucketDir := path.Join(fs.root, bucket) + bucketDir := filepath.Join(fs.root, bucket) // check if bucket exists if _, err := os.Stat(bucketDir); err == nil { @@ -95,7 +94,7 @@ func (fs *fsDriver) GetBucketMetadata(bucket string) (drivers.BucketMetadata, er return drivers.BucketMetadata{}, iodine.New(drivers.BucketNameInvalid{Bucket: bucket}, nil) } // get bucket path - bucketDir := path.Join(fs.root, bucket) + bucketDir := filepath.Join(fs.root, bucket) bucketMetadata := drivers.BucketMetadata{} fi, err := os.Stat(bucketDir) // check if bucket exists @@ -140,7 +139,7 @@ func (fs *fsDriver) SetBucketMetadata(bucket, acl string) error { return iodine.New(drivers.InvalidACL{ACL: acl}, nil) } // get bucket path - bucketDir := path.Join(fs.root, bucket) + bucketDir := filepath.Join(fs.root, bucket) err := os.Chmod(bucketDir, aclToPerm(acl)) if err != nil { return iodine.New(err, nil) @@ -160,7 +159,7 @@ func (fs *fsDriver) ListObjects(bucket string, resources drivers.BucketResources return []drivers.ObjectMetadata{}, resources, iodine.New(drivers.ObjectNameInvalid{Bucket: bucket, Object: resources.Prefix}, nil) } - rootPrefix := path.Join(fs.root, bucket) + rootPrefix := filepath.Join(fs.root, bucket) // check bucket exists if _, err := os.Stat(rootPrefix); os.IsNotExist(err) { return []drivers.ObjectMetadata{}, resources, iodine.New(drivers.BucketNotFound{Bucket: bucket}, nil) diff --git a/pkg/storage/drivers/fs/fs_multipart.go b/pkg/storage/drivers/fs/fs_multipart.go index e2f89878a..e6ba5b876 100644 --- a/pkg/storage/drivers/fs/fs_multipart.go +++ b/pkg/storage/drivers/fs/fs_multipart.go @@ -1,3 +1,19 @@ +/* + * Mini Object Storage, (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package filesystem import ( @@ -13,7 +29,7 @@ import ( "io/ioutil" "math/rand" "os" - "path" + "path/filepath" "sort" "strconv" "strings" @@ -37,7 +53,7 @@ type Multiparts struct { } func (fs *fsDriver) loadActiveSessions(bucket string) { - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) if err != nil { return @@ -112,7 +128,7 @@ func (fs *fsDriver) ListMultipartUploads(bucket string, resources drivers.Bucket if !drivers.IsValidBucket(bucket) { return drivers.BucketMultipartResourcesMetadata{}, iodine.New(drivers.BucketNameInvalid{Bucket: bucket}, nil) } - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) // check bucket exists if os.IsNotExist(err) { @@ -207,7 +223,7 @@ func (fs *fsDriver) NewMultipartUpload(bucket, key, contentType string) (string, return "", iodine.New(drivers.ObjectNameInvalid{Object: key}, nil) } - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) // check bucket exists if os.IsNotExist(err) { @@ -216,8 +232,8 @@ func (fs *fsDriver) NewMultipartUpload(bucket, key, contentType string) (string, if err != nil { return "", iodine.New(drivers.InternalError{}, nil) } - objectPath := path.Join(bucketPath, key) - objectDir := path.Dir(objectPath) + objectPath := filepath.Join(bucketPath, key) + objectDir := filepath.Dir(objectPath) if _, err := os.Stat(objectDir); os.IsNotExist(err) { err = os.MkdirAll(objectDir, 0700) if err != nil { @@ -318,7 +334,7 @@ func (fs *fsDriver) CreateObjectPart(bucket, key, uploadID string, partID int, c expectedMD5Sum = hex.EncodeToString(expectedMD5SumBytes) } - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) // check bucket exists @@ -329,8 +345,8 @@ func (fs *fsDriver) CreateObjectPart(bucket, key, uploadID string, partID int, c return "", iodine.New(drivers.InternalError{}, nil) } - objectPath := path.Join(bucketPath, key) - objectDir := path.Dir(objectPath) + objectPath := filepath.Join(bucketPath, key) + objectDir := filepath.Dir(objectPath) if _, err := os.Stat(objectDir); os.IsNotExist(err) { err = os.MkdirAll(objectDir, 0700) if err != nil { @@ -400,7 +416,7 @@ func (fs *fsDriver) CompleteMultipartUpload(bucket, key, uploadID string, parts return "", iodine.New(drivers.InvalidUploadID{UploadID: uploadID}, nil) } - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) // check bucket exists if os.IsNotExist(err) { @@ -410,7 +426,7 @@ func (fs *fsDriver) CompleteMultipartUpload(bucket, key, uploadID string, parts return "", iodine.New(drivers.InternalError{}, nil) } - objectPath := path.Join(bucketPath, key) + objectPath := filepath.Join(bucketPath, key) // check if object exists if _, err := os.Stat(objectPath); !os.IsNotExist(err) { return "", iodine.New(drivers.ObjectExists{ @@ -506,7 +522,7 @@ func (fs *fsDriver) ListObjectParts(bucket, key string, resources drivers.Object startPartNumber = objectResourcesMetadata.PartNumberMarker } - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) // check bucket exists if os.IsNotExist(err) { @@ -516,7 +532,7 @@ func (fs *fsDriver) ListObjectParts(bucket, key string, resources drivers.Object return drivers.ObjectResourcesMetadata{}, iodine.New(drivers.InternalError{}, nil) } - objectPath := path.Join(bucketPath, key) + objectPath := filepath.Join(bucketPath, key) multiPartfile, err := os.OpenFile(objectPath+"$multiparts", os.O_RDONLY, 0600) if err != nil { return drivers.ObjectResourcesMetadata{}, iodine.New(err, nil) @@ -563,7 +579,7 @@ func (fs *fsDriver) AbortMultipartUpload(bucket, key, uploadID string) error { return iodine.New(drivers.InvalidUploadID{UploadID: uploadID}, nil) } - bucketPath := path.Join(fs.root, bucket) + bucketPath := filepath.Join(fs.root, bucket) _, err := os.Stat(bucketPath) // check bucket exists if os.IsNotExist(err) { @@ -573,7 +589,7 @@ func (fs *fsDriver) AbortMultipartUpload(bucket, key, uploadID string) error { return iodine.New(drivers.InternalError{}, nil) } - objectPath := path.Join(bucketPath, key) + objectPath := filepath.Join(bucketPath, key) multiPartfile, err := os.OpenFile(objectPath+"$multiparts", os.O_RDWR, 0600) if err != nil { return iodine.New(err, nil) diff --git a/pkg/storage/drivers/fs/fs_object.go b/pkg/storage/drivers/fs/fs_object.go index 5437e3dae..be61332d3 100644 --- a/pkg/storage/drivers/fs/fs_object.go +++ b/pkg/storage/drivers/fs/fs_object.go @@ -20,7 +20,7 @@ import ( "bytes" "io" "os" - "path" + "path/filepath" "strings" "crypto/md5" @@ -47,7 +47,7 @@ func (fs *fsDriver) GetPartialObject(w io.Writer, bucket, object string, start, return 0, iodine.New(drivers.ObjectNameInvalid{Bucket: bucket, Object: object}, nil) } - objectPath := path.Join(fs.root, bucket, object) + objectPath := filepath.Join(fs.root, bucket, object) filestat, err := os.Stat(objectPath) switch err := err.(type) { case nil: @@ -94,7 +94,7 @@ func (fs *fsDriver) GetObject(w io.Writer, bucket string, object string) (int64, if drivers.IsValidObjectName(object) == false { return 0, iodine.New(drivers.ObjectNameInvalid{Bucket: bucket, Object: object}, nil) } - objectPath := path.Join(fs.root, bucket, object) + objectPath := filepath.Join(fs.root, bucket, object) filestat, err := os.Stat(objectPath) switch err := err.(type) { case nil: @@ -134,7 +134,7 @@ func (fs *fsDriver) GetObjectMetadata(bucket, object string) (drivers.ObjectMeta return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNameInvalid{Bucket: bucket, Object: bucket}, nil) } - // Do not use path.Join() since path.Join strips off any object names with '/', use them as is + // Do not use filepath.Join() since filepath.Join strips off any object names with '/', use them as is // in a static manner so that we can send a proper 'ObjectNotFound' reply back upon os.Stat() objectPath := fs.root + "/" + bucket + "/" + object stat, err := os.Stat(objectPath) @@ -166,7 +166,7 @@ func (fs *fsDriver) GetObjectMetadata(bucket, object string) (drivers.ObjectMeta } contentType = strings.TrimSpace(contentType) - etag := bucket + "#" + path.Base(object) + etag := bucket + "#" + filepath.Base(object) if len(deserializedMetadata.Md5sum) != 0 { etag = hex.EncodeToString(deserializedMetadata.Md5sum) } @@ -213,7 +213,7 @@ func (fs *fsDriver) CreateObject(bucket, key, contentType, expectedMD5Sum string } // check bucket exists - if _, err := os.Stat(path.Join(fs.root, bucket)); os.IsNotExist(err) { + if _, err := os.Stat(filepath.Join(fs.root, bucket)); os.IsNotExist(err) { return "", iodine.New(drivers.BucketNotFound{Bucket: bucket}, nil) } @@ -229,8 +229,8 @@ func (fs *fsDriver) CreateObject(bucket, key, contentType, expectedMD5Sum string contentType = strings.TrimSpace(contentType) // get object path - objectPath := path.Join(fs.root, bucket, key) - objectDir := path.Dir(objectPath) + objectPath := filepath.Join(fs.root, bucket, key) + objectDir := filepath.Dir(objectPath) if _, err := os.Stat(objectDir); os.IsNotExist(err) { err = os.MkdirAll(objectDir, 0700) if err != nil {