mirror of
https://github.com/minio/minio.git
synced 2025-11-20 09:56:07 -05:00
Use filepath everywhere instead of path.{} functions for portability - fixes #656
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user