Merge pull request #788 from harshavardhana/pr_out_add_windows_specific_path_normalizer

Add windows specific path normalizer
This commit is contained in:
Harshavardhana
2015-06-12 18:42:11 -07:00
4 changed files with 72 additions and 2 deletions
+7
View File
@@ -41,3 +41,10 @@ type NotFolder GenericFileError
func (e NotFolder) Error() string {
return "Requested file ‘" + e.path + "’ is not a folder"
}
// EmptyPath (EINVAL) - invalid argument
type EmptyPath struct{}
func (e EmptyPath) Error() string {
return "Invalid path, path cannot be empty"
}
+6 -2
View File
@@ -36,9 +36,13 @@ type fsClient struct {
// New - instantiate a new fs client
func New(path string) (client.Client, error) {
if strings.TrimSpace(path) == "" {
return nil, iodine.New(errors.New("Path is empty."), nil)
return nil, iodine.New(EmptyPath{}, nil)
}
var err error
path, err = normalizePath(path)
if err != nil {
return nil, iodine.New(err, nil)
}
return &fsClient{path: path}, nil
}
+23
View File
@@ -0,0 +1,23 @@
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
/*
* Minio Client (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs 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 fs
func normalizePath(path string) (string, error) {
return path, nil
}
+36
View File
@@ -0,0 +1,36 @@
// +build windows
/*
* Minio Client (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this fs 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 fs
import (
"path/filepath"
"syscall"
"github.com/minio/minio/pkg/iodine"
)
func normalizePath(path string) (string, error) {
if filepath.VolumeName(path) == "" && filepath.HasPrefix(path, "\\") {
path, err = syscall.FullPath(path)
if err != nil {
return "", iodine.New(err, nil)
}
}
return path, nil
}