add option to overwrite automatically

This commit is contained in:
Zack Scholl 2021-04-16 15:14:21 -07:00
parent be5ceae8c7
commit babfd5f35f
2 changed files with 7 additions and 3 deletions

View File

@ -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 = ""

View File

@ -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))