From 7ec954a78bf0e1fc6a2841ed6a71eedd461c8832 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 22 Apr 2015 13:11:13 -0700 Subject: [PATCH] Fix a crash on windows when source is malformed --- cmd-options.go | 2 +- pkg/client/fs/fs_errors.go | 6 +++--- pkg/client/fs/fs_unix.go | 8 ++++---- pkg/client/fs/fs_windows.go | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd-options.go b/cmd-options.go index f07ab722..2c46f55c 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -54,7 +54,7 @@ EXAMPLES: $ mc {{.Name}} backup/... http://localhost:9000/archive/ https://s3.amazonaws.com/archive/ 4. Copy an object from Amazon S3 object storage to local filesystem on Windows. - $ mc {{.Name}} https://s3.amazonaws.com/jukebox/vulcan_lute.ogg C:\Users\Surak\sleep.ogg + $ mc {{.Name}} s3:documents/2014/... Documents\backup\2014 `, } diff --git a/pkg/client/fs/fs_errors.go b/pkg/client/fs/fs_errors.go index d1188501..d112b5cf 100644 --- a/pkg/client/fs/fs_errors.go +++ b/pkg/client/fs/fs_errors.go @@ -9,19 +9,19 @@ type GenericFileError struct { type FileNotFound GenericFileError func (e FileNotFound) Error() string { - return "Requested file " + e.path + "not found" + return "Requested file " + e.path + " not found" } // FileISDir (EISDIR) - accessed file is a directory type FileISDir GenericFileError func (e FileISDir) Error() string { - return "Requested file " + e.path + "is a directory" + return "Requested file " + e.path + " is a directory" } // FileNotDir (ENOTDIR) - accessed file is not a directory type FileNotDir GenericFileError func (e FileNotDir) Error() string { - return "Requested file " + e.path + "is not a directory" + return "Requested file " + e.path + " is not a directory" } diff --git a/pkg/client/fs/fs_unix.go b/pkg/client/fs/fs_unix.go index 7c776933..f54c1e83 100644 --- a/pkg/client/fs/fs_unix.go +++ b/pkg/client/fs/fs_unix.go @@ -46,16 +46,16 @@ func New(path string) client.Client { /// Object operations // getObjectMetadata - wrapper function to get file stat func (f *fsClient) getObjectMetadata() (os.FileInfo, error) { - st, err := os.Stat(f.path) + st, err := os.Stat(filepath.Clean(f.path)) if os.IsNotExist(err) { return nil, iodine.New(FileNotFound{path: f.path}, nil) } - if st.IsDir() { - return nil, iodine.New(FileISDir{path: f.path}, nil) - } if err != nil { return nil, iodine.New(err, nil) } + if st.IsDir() { + return nil, iodine.New(FileISDir{path: f.path}, nil) + } return st, nil } diff --git a/pkg/client/fs/fs_windows.go b/pkg/client/fs/fs_windows.go index 49918664..6cd01b61 100644 --- a/pkg/client/fs/fs_windows.go +++ b/pkg/client/fs/fs_windows.go @@ -47,12 +47,12 @@ func (f *fsClient) getObjectMetadata() (os.FileInfo, error) { if os.IsNotExist(err) { return nil, iodine.New(FileNotFound{path: f.path}, nil) } - if st.IsDir() { - return nil, iodine.New(FileISDir{path: f.path}, nil) - } if err != nil { return nil, iodine.New(err, nil) } + if st.IsDir() { + return nil, iodine.New(FileISDir{path: f.path}, nil) + } return st, nil }