diff --git a/pkg/client/fs/errors.go b/pkg/client/fs/errors.go index 1a442731..12299bae 100644 --- a/pkg/client/fs/errors.go +++ b/pkg/client/fs/errors.go @@ -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" +} diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index d0bb610e..666a980e 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -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 } diff --git a/pkg/client/fs/fs_unix.go b/pkg/client/fs/fs_unix.go new file mode 100644 index 00000000..0cc1d2db --- /dev/null +++ b/pkg/client/fs/fs_unix.go @@ -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 +} diff --git a/pkg/client/fs/fs_windows.go b/pkg/client/fs/fs_windows.go new file mode 100644 index 00000000..82e2288e --- /dev/null +++ b/pkg/client/fs/fs_windows.go @@ -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 +}