Merge pull request #1279 from abperiasamy/review-multiple-cmds

review of cp ls mirror pipe and rm
This commit is contained in:
Harshavardhana
2015-11-12 01:42:03 -08:00
8 changed files with 51 additions and 47 deletions
+24 -18
View File
@@ -34,46 +34,52 @@ import (
"github.com/minio/minio-xl/pkg/probe"
)
// Copy files and folders from many sources to a single destination.
// cp specific flags.
var (
cpFlagForce = cli.BoolFlag{
Name: "force",
Usage: "Force overwrite of an existing target(s).",
}
)
// Copy command.
var cpCmd = cli.Command{
Name: "cp",
Usage: "Copy files and folders from many sources to a single destination.",
Usage: "Copy one or more objects to a target.",
Action: mainCopy,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force",
Usage: "force a dangerous remove operation.",
},
},
Flags: []cli.Flag{cpFlagForce},
CustomHelpTemplate: `NAME:
mc {{.Name}} - {{.Usage}}
USAGE:
mc {{.Name}} SOURCE [SOURCE...] TARGET
mc {{.Name}} [OPTIONS] SOURCE [SOURCE...] TARGET
OPTIONS:
--force - Force overwrite of an existing target(s).
EXAMPLES:
1. Copy list of objects from local file system to Amazon S3 cloud storage.
1. Copy a list of objects from local file system to Amazon S3 cloud storage.
$ mc {{.Name}} Music/*.ogg https://s3.amazonaws.com/jukebox/
2. Copy a bucket recursively from Minio cloud storage to Amazon S3 cloud storage.
$ mc {{.Name}} https://play.minio.io:9000/photos/burningman2011... https://s3.amazonaws.com/private-photos/burningman/
$ mc {{.Name}} https://play.minio.io:9000/photobucket/burningman2011... https://s3.amazonaws.com/mybucket/
3. Copy multiple local folders recursively to Minio cloud storage.
$ mc {{.Name}} backup/2014/... backup/2015/... https://play.minio.io:9000/archive/
4. Copy a bucket recursively from aliased Amazon S3 cloud storage to local filesystem on Windows.
$ mc {{.Name}} s3/documents/2014/... C:\backup\2014
$ mc {{.Name}} s3/documents/2014/... C:\Backups\2014
5. Copy an object of non english characters to Amazon S3 cloud storage.
$ mc {{.Name}} 本語 s3/andoria/本語
5. Copy an object with name containing unicode characters to Amazon S3 cloud storage.
$ mc {{.Name}} 本語 s3/andoria/
6. Copy local folder with space characters to Amazon S3 cloud storage.
6. Copy a local folder with space separated characters to Amazon S3 cloud storage.
$ mc {{.Name}} 'workdir/documents/May 2014...' s3/miniocloud
`,
}
var (
cpForceFlag = false // cp specific force flag set via command line
cpIsForce = false // cp specific force flag set via command line
)
// copyMessage container for file copy messages
@@ -176,7 +182,7 @@ func doPrepareCopyURLs(session *sessionV3, trapCh <-chan bool) {
}
// will be true if '--force' is provided on the command line.
cpForceFlag = session.Header.CommandBoolFlag.Value
cpIsForce = session.Header.CommandBoolFlag.Value
URLsCh := prepareCopyURLs(sourceURLs, targetURL)
done := false
@@ -329,7 +335,7 @@ func doCopySession(session *sessionV3) {
wg.Wait()
}
// mainCopy is bound to sub-command
// mainCopy is the entry point for cp command.
func mainCopy(ctx *cli.Context) {
checkCopySyntax(ctx)
+3 -3
View File
@@ -248,7 +248,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) copyURLs {
}
_, _, err = url2Stat(targetURL)
if err == nil && !cpForceFlag {
if err == nil && !cpIsForce {
return copyURLs{Error: errOverWriteNotAllowed(targetURL).Trace()}
}
@@ -344,9 +344,9 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
newTargetURL.Path = filepath.Join(newTargetURL.Path,
strings.TrimPrefix(sourceContent.Content.URL.Path, url2Dir(sourceURL)))
// verify if destination exists, and cpForceFlag is not set do not proceed.
// verify if destination exists, and cpIsForce is not set do not proceed.
_, _, err := url2Stat(newTargetURL.String())
if err == nil && !cpForceFlag {
if err == nil && !cpIsForce {
copyURLsCh <- copyURLs{Error: errOverWriteNotAllowed(newTargetURL.String()).Trace()}
return
}
+1 -1
View File
@@ -29,7 +29,7 @@ import (
var (
lsFlagIncomplete = cli.BoolFlag{
Name: "incomplete, I",
Usage: "remove incomplete uploads.",
Usage: "Remove incomplete uploads.",
}
)
+2 -2
View File
@@ -138,7 +138,7 @@ func findClosestCommands(command string) []string {
}
func registerApp() *cli.App {
// Register all the commands
// Register all the commands (refer flags.go)
registerCmd(lsCmd) // List contents of a bucket.
registerCmd(mbCmd) // Make a bucket.
registerCmd(catCmd) // Display contents of a file.
@@ -154,7 +154,7 @@ func registerApp() *cli.App {
registerCmd(updateCmd) // Check for new software updates.
registerCmd(versionCmd) // Print version.
// register all the flags
// register all the flags (refer flags.go)
registerFlag(configFlag) // Path to configuration folder.
registerFlag(quietFlag) // Suppress chatty console output.
registerFlag(mimicFlag) // Behave like operating system tools. Use with shell aliases.
+17 -15
View File
@@ -33,22 +33,28 @@ import (
"github.com/minio/minio-xl/pkg/probe"
)
// mirror specific flags.
var (
mirrorFlagForce = cli.BoolFlag{
Name: "force",
Usage: "Force overwrite of an existing target(s).",
}
)
// Mirror folders recursively from a single source to many destinations
var mirrorCmd = cli.Command{
Name: "mirror",
Usage: "Mirror folders recursively from a single source to many destinations.",
Action: mainMirror,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force",
Usage: "force a dangerous remove operation.",
},
},
Flags: []cli.Flag{mirrorFlagForce},
CustomHelpTemplate: `NAME:
mc {{.Name}} - {{.Usage}}
USAGE:
mc {{.Name}} SOURCE TARGET [TARGET...]
mc {{.Name}} [OPTIONS] SOURCE TARGET [TARGET...]
OPTIONS:
--force - Force overwrite of an existing target(s).
EXAMPLES:
1. Mirror a bucket recursively from Minio cloud storage to a bucket on Amazon S3 cloud storage.
@@ -59,17 +65,11 @@ EXAMPLES:
3. Mirror a bucket from aliased Amazon S3 cloud storage to multiple folders on Windows.
$ mc {{.Name}} s3/documents/2014/ C:\backup\2014 C:\shared\volume\backup\2014
4. Mirror a local folder of non english character recursively to Amazon s3 cloud storage and Minio cloud storage.
$ mc {{.Name}} 本語/ s3/mylocaldocuments play/backup
5. Mirror a local folder with space characters to Amazon s3 cloud storage
$ mc {{.Name}} 'workdir/documents/Aug 2015' s3/miniocloud
`,
}
var (
mirrorForceFlag = false // mirror specific force flag set via command line
mirrorIsForce = false // mirror specific force flag set via command line
)
// mirrorMessage container for file mirror messages
@@ -173,7 +173,7 @@ func doPrepareMirrorURLs(session *sessionV3, trapCh <-chan bool) {
}
// will be true if '--force' is provided on the command line.
mirrorForceFlag = session.Header.CommandBoolFlag.Value
mirrorIsForce = session.Header.CommandBoolFlag.Value
URLsCh := prepareMirrorURLs(sourceURL, targetURLs)
done := false
@@ -221,6 +221,7 @@ func doPrepareMirrorURLs(session *sessionV3, trapCh <-chan bool) {
session.Save()
}
// Session'fied mirror command.
func doMirrorSession(session *sessionV3) {
trapCh := signalTrap(os.Interrupt, os.Kill)
@@ -325,6 +326,7 @@ func doMirrorSession(session *sessionV3) {
wg.Wait()
}
// Main entry point for mirror command.
func mainMirror(ctx *cli.Context) {
checkMirrorSyntax(ctx)
+1 -1
View File
@@ -218,7 +218,7 @@ func deltaSourceTargets(sourceURL string, targetURLs []string, mirrorURLsCh chan
// source and target have same content type.
if srcContent.Type.IsRegular() && targetContents[i].Type.IsRegular() {
if srcContent.Size != targetContents[i].Size {
if !mirrorForceFlag {
if !mirrorIsForce {
mirrorURLsCh <- mirrorURLs{
Error: errOverWriteNotAllowed(targetContents[i].URL.String()).Trace(srcContent.URL.String()),
}
+2 -6
View File
@@ -39,15 +39,11 @@ EXAMPLES:
1. Write contents of stdin to an object on Amazon S3 cloud storage.
$ mc {{.Name}} https://s3.amazonaws.com/personalbuck/meeting-notes.txt
2. Concatinate part files to an object on Amazon S3 cloud storage and Google Cloud Storage.
$ cat part1.img part2.img | mc {{.Name}} https://s3.amazonaws.com/ferenginar/gnuos.iso https://storage.googleapis.com/miniocloud/gnuos.iso
2. Copy an ISO image to an object on Amazon S3 cloud storage and Google Cloud Storage simultaneously.
$ cat debian-8.2.iso | mc {{.Name}} https://s3.amazonaws.com/ferenginar/gnuos.iso https://storage.googleapis.com/miniocloud/gnuos.iso
3. Stream MySQL database dump to Amazon S3 directly.
$ mysqldump -u root -p ******* accountsdb | mc {{.Name}} https://s3.amazonaws.com/ferenginar/backups/accountsdb-oct-9-2015.sql
4. Stream a zip file to two object storage servers simultaneously.
$ cat ~/myphotos.zip | mc {{.Name}} https://s3.amazonaws.com/mybucket/photos.zip https://minio.mystartup.io:9000/backup/photos.zip
`,
}
+1 -1
View File
@@ -32,7 +32,7 @@ import (
var (
rmFlagForce = cli.BoolFlag{
Name: "force",
Usage: "force a dangerous remove operation.",
Usage: "Force a dangerous remove operation.",
}
rmFlagIncomplete = cli.BoolFlag{