From 3950402c896e34b28e95758bee70111d80cfbf97 Mon Sep 17 00:00:00 2001 From: "Anand Babu (AB) Periasamy" Date: Thu, 12 Nov 2015 01:01:03 -0800 Subject: [PATCH] review of cp ls mirror pipe and rm --- cp-main.go | 42 ++++++++++++++++++++++++------------------ cp-url.go | 6 +++--- ls-main.go | 2 +- main.go | 4 ++-- mirror-main.go | 32 +++++++++++++++++--------------- mirror-url.go | 2 +- pipe-main.go | 8 ++------ rm-main.go | 2 +- 8 files changed, 51 insertions(+), 47 deletions(-) diff --git a/cp-main.go b/cp-main.go index 8983231c..31289ab7 100644 --- a/cp-main.go +++ b/cp-main.go @@ -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) diff --git a/cp-url.go b/cp-url.go index eb3c870b..ff8ec079 100644 --- a/cp-url.go +++ b/cp-url.go @@ -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 } diff --git a/ls-main.go b/ls-main.go index 0467f5dc..033cd4e8 100644 --- a/ls-main.go +++ b/ls-main.go @@ -29,7 +29,7 @@ import ( var ( lsFlagIncomplete = cli.BoolFlag{ Name: "incomplete, I", - Usage: "remove incomplete uploads.", + Usage: "Remove incomplete uploads.", } ) diff --git a/main.go b/main.go index 94e87c80..3bd4ff38 100644 --- a/main.go +++ b/main.go @@ -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. diff --git a/mirror-main.go b/mirror-main.go index 701ff9a6..5aafa5ff 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -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) diff --git a/mirror-url.go b/mirror-url.go index 1a832323..4e61886b 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -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()), } diff --git a/pipe-main.go b/pipe-main.go index 7acb0b04..b42c06a7 100644 --- a/pipe-main.go +++ b/pipe-main.go @@ -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 - `, } diff --git a/rm-main.go b/rm-main.go index 119b247b..a444a8d4 100644 --- a/rm-main.go +++ b/rm-main.go @@ -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{