posix: filepath shouldn't be used anymore use path.Join (#1486)

master
Harshavardhana 9 years ago committed by Anand Babu (AB) Periasamy
parent 82fbe908a3
commit ad40036cba
  1. 6
      bucket-handlers.go
  2. 5
      posix-dir-common.go
  3. 2
      posix-dir-nix.go
  4. 33
      posix.go
  5. 5
      xl-erasure-v1-common.go
  6. 4
      xl-erasure-v1-healfile.go

@ -594,9 +594,9 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
} }
encodedSuccessResponse := encodeResponse(PostResponse{ encodedSuccessResponse := encodeResponse(PostResponse{
Location: getObjectLocation(bucket, object), // TODO Full URL is preferred Location: getObjectLocation(bucket, object), // TODO Full URL is preferred
Bucket: bucket, Bucket: bucket,
Key: object, Key: object,
ETag: md5Sum, ETag: md5Sum,
}) })
setCommonHeaders(w) setCommonHeaders(w)
writeSuccessResponse(w, encodedSuccessResponse) writeSuccessResponse(w, encodedSuccessResponse)

@ -108,10 +108,9 @@ func treeWalk(bucketDir, prefixDir, entryPrefixMatch, marker string, recursive b
fileInfo.Mode = dirent.mode fileInfo.Mode = dirent.mode
} }
if fileInfo.Mode.IsDir() { if fileInfo.Mode.IsDir() {
// Add os.PathSeparator suffix again for directories as // Add "/" suffix again for directories as
// filepath.Join would have removed it.
fileInfo.Size = 0 fileInfo.Size = 0
fileInfo.Name += string(os.PathSeparator) fileInfo.Name += "/"
} }
return fileInfo, nil return fileInfo, nil
} }

@ -132,7 +132,7 @@ func scandir(dirPath string, filter func(fsDirent) bool, namesOnly bool) ([]fsDi
dirent.name = path.Join(dirPath, dirent.name) dirent.name = path.Join(dirPath, dirent.name)
} }
if dirent.IsDir() { if dirent.IsDir() {
dirent.name += string(os.PathSeparator) dirent.name += "/"
dirent.size = 0 dirent.size = 0
} }
if filter == nil || filter(dirent) { if filter == nil || filter(dirent) {

@ -33,7 +33,7 @@ import (
) )
const ( const (
fsListLimit = 1000 fsListLimit = 1000
fsMinSpacePercent = 5 fsMinSpacePercent = 5
) )
@ -160,7 +160,7 @@ func removeDuplicateVols(volsInfo []VolInfo) []VolInfo {
func getAllUniqueVols(dirPath string) ([]VolInfo, error) { func getAllUniqueVols(dirPath string) ([]VolInfo, error) {
volumeFn := func(dirent fsDirent) bool { volumeFn := func(dirent fsDirent) bool {
// Return all directories. // Return all directories.
return dirent.IsDir() && isValidVolname(filepath.Clean(dirent.name)) return dirent.IsDir() && isValidVolname(path.Clean(dirent.name))
} }
namesOnly := true // Returned are only names. namesOnly := true // Returned are only names.
dirents, err := scandir(dirPath, volumeFn, namesOnly) dirents, err := scandir(dirPath, volumeFn, namesOnly)
@ -173,10 +173,10 @@ func getAllUniqueVols(dirPath string) ([]VolInfo, error) {
} }
var volsInfo []VolInfo var volsInfo []VolInfo
for _, dirent := range dirents { for _, dirent := range dirents {
fi, err := os.Stat(filepath.Join(dirPath, dirent.name)) fi, err := os.Stat(pathJoin(dirPath, dirent.name))
if err != nil { if err != nil {
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"path": filepath.Join(dirPath, dirent.name), "path": pathJoin(dirPath, dirent.name),
}).Debugf("Stat failed with error %s", err) }).Debugf("Stat failed with error %s", err)
return nil, err return nil, err
} }
@ -198,7 +198,7 @@ func (s fsStorage) getVolumeDir(volume string) (string, error) {
if !isValidVolname(volume) { if !isValidVolname(volume) {
return "", errInvalidArgument return "", errInvalidArgument
} }
volumeDir := filepath.Join(s.diskPath, volume) volumeDir := pathJoin(s.diskPath, volume)
_, err := os.Stat(volumeDir) _, err := os.Stat(volumeDir)
if err == nil { if err == nil {
return volumeDir, nil return volumeDir, nil
@ -210,12 +210,10 @@ func (s fsStorage) getVolumeDir(volume string) (string, error) {
return volumeDir, errVolumeNotFound return volumeDir, errVolumeNotFound
} }
for _, vol := range volsInfo { for _, vol := range volsInfo {
// Verify if lowercase version of // Verify if lowercase version of the volume is equal to
// the volume // the incoming volume, then use the proper name.
// is equal to the incoming volume, then use the proper
// name.
if strings.ToLower(vol.Name) == volume { if strings.ToLower(vol.Name) == volume {
volumeDir = filepath.Join(s.diskPath, vol.Name) volumeDir = pathJoin(s.diskPath, vol.Name)
return volumeDir, nil return volumeDir, nil
} }
} }
@ -544,7 +542,7 @@ func (s fsStorage) ReadFile(volume string, path string, offset int64) (readClose
return nil, err return nil, err
} }
filePath := filepath.Join(volumeDir, filepath.FromSlash(path)) filePath := pathJoin(volumeDir, path)
file, err := os.Open(filePath) file, err := os.Open(filePath)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
@ -600,7 +598,7 @@ func (s fsStorage) CreateFile(volume, path string) (writeCloser io.WriteCloser,
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil {
return nil, err return nil, err
} }
filePath := filepath.Join(volumeDir, path) filePath := pathJoin(volumeDir, path)
// Verify if the file already exists and is not of regular type. // Verify if the file already exists and is not of regular type.
var st os.FileInfo var st os.FileInfo
if st, err = os.Stat(filePath); err == nil { if st, err = os.Stat(filePath); err == nil {
@ -634,7 +632,7 @@ func (s fsStorage) StatFile(volume, path string) (file FileInfo, err error) {
return FileInfo{}, err return FileInfo{}, err
} }
filePath := filepath.Join(volumeDir, filepath.FromSlash(path)) filePath := pathJoin(volumeDir, path)
st, err := os.Stat(filePath) st, err := os.Stat(filePath)
if err != nil { if err != nil {
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
@ -712,10 +710,10 @@ func deleteFile(basePath, deletePath string) error {
return err return err
} }
// Recursively go down the next path and delete again. // Recursively go down the next path and delete again.
if err := deleteFile(basePath, filepath.Dir(deletePath)); err != nil { if err := deleteFile(basePath, path.Dir(deletePath)); err != nil {
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"basePath": basePath, "basePath": basePath,
"deleteDir": filepath.Dir(deletePath), "deleteDir": path.Dir(deletePath),
}).Debugf("deleteFile failed with %s", err) }).Debugf("deleteFile failed with %s", err)
return err return err
} }
@ -735,10 +733,7 @@ func (s fsStorage) DeleteFile(volume, path string) error {
// Following code is needed so that we retain "/" suffix if any in // Following code is needed so that we retain "/" suffix if any in
// path argument. // path argument.
filePath := filepath.Join(volumeDir, filepath.FromSlash(path)) filePath := pathJoin(volumeDir, path)
if strings.HasSuffix(filepath.FromSlash(path), string(os.PathSeparator)) {
filePath = filePath + string(os.PathSeparator)
}
// Delete file and delete parent directory as well if its empty. // Delete file and delete parent directory as well if its empty.
return deleteFile(volumeDir, filePath) return deleteFile(volumeDir, filePath)

@ -19,7 +19,6 @@ package main
import ( import (
"errors" "errors"
slashpath "path" slashpath "path"
"path/filepath"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
) )
@ -145,8 +144,8 @@ func (xl XL) getPartsMetadata(volume, path string) ([]xlMetaV1, []error) {
// Returns collection of errors, indexed in accordance with input // Returns collection of errors, indexed in accordance with input
// updateParts order. // updateParts order.
// Write lockNS() should be done by caller. // Write lockNS() should be done by caller.
func (xl XL) setPartsMetadata(volume, path string, metadata xlMetaV1, updateParts []bool) []error { func (xl XL) updatePartsMetadata(volume, path string, metadata xlMetaV1, updateParts []bool) []error {
xlMetaV1FilePath := filepath.Join(path, xlMetaV1File) xlMetaV1FilePath := pathJoin(path, xlMetaV1File)
errs := make([]error, len(xl.storageDisks)) errs := make([]error, len(xl.storageDisks))
for index := range updateParts { for index := range updateParts {

@ -206,8 +206,8 @@ func (xl XL) healFile(volume string, path string) error {
writer.Close() writer.Close()
} }
// Update the quorum metadata after selfheal. // Update the quorum metadata after heal.
errs := xl.setPartsMetadata(volume, path, metadata, needsHeal) errs := xl.updatePartsMetadata(volume, path, metadata, needsHeal)
for index, healNeeded := range needsHeal { for index, healNeeded := range needsHeal {
if healNeeded && errs[index] != nil { if healNeeded && errs[index] != nil {
return errs[index] return errs[index]

Loading…
Cancel
Save