Handle errors properly in cp
This commit is contained in:
@@ -83,26 +83,27 @@ func runCopyCmdMultipleSources(methods clientMethods, urls []string) {
|
||||
newRecursiveSourceConfig, err := getHostConfig(newRecursiveSourceURL)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Unable to read host configuration for the following targets %s from config file [%s]. Reason: [%s].\n",
|
||||
console.Fatalf("Unable to read host configuration for the source %s from config file [%s]. Reason: [%s].\n",
|
||||
newRecursiveSourceURL, mustGetMcConfigPath(), iodine.ToError(err))
|
||||
}
|
||||
err = doCopySingleSourceRecursive(methods, newRecursiveSourceURL, targetURL, newRecursiveSourceConfig, targetConfig)
|
||||
if err != nil {
|
||||
log.Debug.Println(err)
|
||||
console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", newRecursiveSourceURL,
|
||||
console.Fatalf("Failed to copy from source %s to target %s. Reason: [%s].\n", newRecursiveSourceURL,
|
||||
targetURL, iodine.ToError(err))
|
||||
}
|
||||
}
|
||||
newRegularSourceURLConfigMap, err := getHostConfigs(newRegularSourceURLs)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Unable to read host configuration for source [%s] from config file [%s]. Reason: [%s].\n",
|
||||
console.Fatalf("Unable to read host configuration for the following sources [%s] from config file [%s]. Reason: [%s].\n",
|
||||
newRegularSourceURLs, mustGetMcConfigPath(), iodine.ToError(err))
|
||||
}
|
||||
err = doCopyMultipleSources(methods, newRegularSourceURLConfigMap, targetURL, targetConfig)
|
||||
if err != nil {
|
||||
log.Debug.Println(err)
|
||||
console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", sourceURLs, targetURL, iodine.ToError(err))
|
||||
console.Fatalf("Failed to copy from following sources [%s] to target %s. Reason: [%s].\n",
|
||||
newRegularSourceURLs, targetURL, iodine.ToError(err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-6
@@ -102,17 +102,17 @@ FLAGS:
|
||||
{{end}}{{ end }}
|
||||
|
||||
EXAMPLES:
|
||||
1. Copy an object from Amazon S3 object storage to local fileystem.
|
||||
1. Copy list of objects from local file system to Amazon S3 object storage
|
||||
$ mc {{.Name}} Music/*.ogg https://s3.amazonaws.com/jukebox/
|
||||
|
||||
2. Copy a bucket recursively from Minio object storage to Amazon S3 object storage
|
||||
$ mc {{.Name}} http://localhost:9000/photos/burningman2011... https://s3.amazonaws.com/burningman/
|
||||
$ mc {{.Name}} http://localhost:9000/photos/burningman2011... https://s3.amazonaws.com/private-photos/burningman/
|
||||
|
||||
3. Copy a local folder recursively to Minio object storage and Amazon S3 object storage
|
||||
$ mc {{.Name}} backup/... http://localhost:9000/archive/
|
||||
3. Copy multiple local folders recursively to Minio object storage
|
||||
$ mc {{.Name}} backup/2014/... backup/2015/... http://localhost:9000/archive/
|
||||
|
||||
4. Copy an object from Amazon S3 object storage to local filesystem on Windows.
|
||||
$ mc {{.Name}} s3:documents/2014/... backup/2014
|
||||
4. Copy a bucket recursively from aliased Amazon S3 object storage to local filesystem on Windows.
|
||||
$ mc {{.Name}} s3:documents/2014/... C:\backup\2014
|
||||
|
||||
`,
|
||||
}
|
||||
@@ -183,6 +183,17 @@ FLAGS:
|
||||
{{end}}{{ end }}
|
||||
|
||||
EXAMPLES:
|
||||
1. Sync an object from local filesystem to Amazon S3 object storage
|
||||
$ mc {{.Name}} star-trek-episode-10-season4.ogg https://s3.amazonaws.com/trekarchive
|
||||
|
||||
2. Sync a bucket recursively from Minio object storage to multiple buckets on Amazon S3 object storage
|
||||
$ mc {{.Name}} http://localhost:9000/photos/2014... https://s3.amazonaws.com/backup-photos https://s3.amazonaws.com/my-photos
|
||||
|
||||
3. Copy a local folder recursively to Minio object storage and Amazon S3 object storage
|
||||
$ mc {{.Name}} backup/... http://localhost:9000/archive https://s3.amazonaws.com/archive
|
||||
|
||||
4. Sync a bucket from aliased Amazon S3 object storage to multiple folders on Windows.
|
||||
$ mc {{.Name}} s3:documents/2014/... C:\backup\2014 C:\shared\volume\backup\2014
|
||||
|
||||
`,
|
||||
}
|
||||
|
||||
+3
-4
@@ -27,9 +27,8 @@ import (
|
||||
|
||||
func runSyncCmd(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code
|
||||
cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
@@ -64,13 +63,13 @@ func runCopyCmdSingleSourceMultipleTargets(methods clientMethods, urls []string)
|
||||
sourceConfig, err := getHostConfig(sourceURL)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Unable to read host configuration for the following targets %s from config file [%s]. Reason: [%s].\n",
|
||||
console.Fatalf("Unable to read host configuration for the source %s from config file [%s]. Reason: [%s].\n",
|
||||
sourceURL, mustGetMcConfigPath(), iodine.ToError(err))
|
||||
}
|
||||
targetURLConfigMap, err := getHostConfigs(targetURLs)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Unable to read host configuration for source [%s] from config file [%s]. Reason: [%s].\n",
|
||||
console.Fatalf("Unable to read host configuration for the following targets [%s] from config file [%s]. Reason: [%s].\n",
|
||||
targetURLs, mustGetMcConfigPath(), iodine.ToError(err))
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
"github.com/minio-io/minio/pkg/iodine"
|
||||
@@ -89,7 +90,22 @@ func doCopySingleSourceRecursive(methods clientMethods, sourceURL, targetURL str
|
||||
continue
|
||||
}
|
||||
newSourceURL, newTargetURL := getNewURLRecursive(sourceURL, targetURL, itemCh.Item.Name)
|
||||
doCopySingleSource(methods, newSourceURL, newTargetURL, sourceConfig, targetConfig)
|
||||
if err := doCopySingleSource(methods, newSourceURL, newTargetURL, sourceConfig, targetConfig); err != nil {
|
||||
// verify for directory related errors, if "open" failed on directories ignore those errors
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
case *os.PathError:
|
||||
switch true {
|
||||
// even with in PathError specific error related to directory reads is ignored
|
||||
// do not ignore any other errors, since they might be valid problems on the filesystem
|
||||
case e.Op == "read" && e.Err.Error() == "is a directory":
|
||||
continue
|
||||
default:
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
default:
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user