diff --git a/src/cli/cli.go b/src/cli/cli.go index 022aab8e..b3fb14d8 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -86,6 +86,7 @@ func Run() (err error) { &cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"}, &cli.BoolFlag{Name: "local", Usage: "force to use only local connections"}, &cli.BoolFlag{Name: "ignore-stdin", Usage: "ignore piped stdin"}, + &cli.BoolFlag{Name: "overwrite", Usage: "do not prompt to overwrite"}, &cli.StringFlag{Name: "ip", Value: "", Usage: "set sender ip if known e.g. 10.0.0.1:9009, [::1]:9009"}, &cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay", EnvVars: []string{"CROC_RELAY"}}, &cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay", EnvVars: []string{"CROC_RELAY6"}}, @@ -130,7 +131,7 @@ func getConfigDir() (homedir string, err error) { log.Error(err) return } - + if envHomedir, isSet := os.LookupEnv("CROC_CONFIG_DIR"); isSet { homedir = envHomedir } else if xdgConfigHome, isSet := os.LookupEnv("XDG_CONFIG_HOME"); isSet { @@ -138,7 +139,7 @@ func getConfigDir() (homedir string, err error) { } else { homedir = path.Join(homedir, ".config", "croc") } - + if _, err = os.Stat(homedir); os.IsNotExist(err) { log.Debugf("creating home directory %s", homedir) err = os.MkdirAll(homedir, 0700) @@ -193,6 +194,7 @@ func send(c *cli.Context) (err error) { RelayPassword: determinePass(c), SendingText: c.String("text") != "", NoCompress: c.Bool("no-compress"), + Overwrite: c.Bool("overwrite"), } if crocOptions.RelayAddress != models.DEFAULT_RELAY { crocOptions.RelayAddress6 = "" @@ -388,6 +390,7 @@ func receive(c *cli.Context) (err error) { RelayPassword: determinePass(c), OnlyLocal: c.Bool("local"), IP: c.String("ip"), + Overwrite: c.Bool("overwrite"), } if crocOptions.RelayAddress != models.DEFAULT_RELAY { crocOptions.RelayAddress6 = "" diff --git a/src/croc/croc.go b/src/croc/croc.go index dfc378c8..bc4f3dd0 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -65,6 +65,7 @@ type Options struct { SendingText bool NoCompress bool IP string + Overwrite bool } // Client holds the state of the croc transfer @@ -1216,7 +1217,7 @@ func (c *Client) updateIfRecipientHasFileInfo() (err error) { log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash) if !bytes.Equal(fileHash, fileInfo.Hash) { log.Debugf("hashes are not equal %x != %x", fileHash, fileInfo.Hash) - if errHash== nil { + if errHash== nil && !c.Options.Overwrite { ans := utils.GetInput(fmt.Sprintf("\rOverwrite '%s'? (y/n) ",path.Join(fileInfo.FolderRemote, fileInfo.Name))) if strings.TrimSpace(strings.ToLower(ans)) != "y" { fmt.Fprintf(os.Stderr,"skipping '%s'",path.Join(fileInfo.FolderRemote, fileInfo.Name))