mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
add option to overwrite automatically
This commit is contained in:
parent
be5ceae8c7
commit
babfd5f35f
2 changed files with 7 additions and 3 deletions
|
@ -86,6 +86,7 @@ func Run() (err error) {
|
||||||
&cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
|
&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: "local", Usage: "force to use only local connections"},
|
||||||
&cli.BoolFlag{Name: "ignore-stdin", Usage: "ignore piped stdin"},
|
&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: "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: "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"}},
|
&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)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if envHomedir, isSet := os.LookupEnv("CROC_CONFIG_DIR"); isSet {
|
if envHomedir, isSet := os.LookupEnv("CROC_CONFIG_DIR"); isSet {
|
||||||
homedir = envHomedir
|
homedir = envHomedir
|
||||||
} else if xdgConfigHome, isSet := os.LookupEnv("XDG_CONFIG_HOME"); isSet {
|
} else if xdgConfigHome, isSet := os.LookupEnv("XDG_CONFIG_HOME"); isSet {
|
||||||
|
@ -138,7 +139,7 @@ func getConfigDir() (homedir string, err error) {
|
||||||
} else {
|
} else {
|
||||||
homedir = path.Join(homedir, ".config", "croc")
|
homedir = path.Join(homedir, ".config", "croc")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = os.Stat(homedir); os.IsNotExist(err) {
|
if _, err = os.Stat(homedir); os.IsNotExist(err) {
|
||||||
log.Debugf("creating home directory %s", homedir)
|
log.Debugf("creating home directory %s", homedir)
|
||||||
err = os.MkdirAll(homedir, 0700)
|
err = os.MkdirAll(homedir, 0700)
|
||||||
|
@ -193,6 +194,7 @@ func send(c *cli.Context) (err error) {
|
||||||
RelayPassword: determinePass(c),
|
RelayPassword: determinePass(c),
|
||||||
SendingText: c.String("text") != "",
|
SendingText: c.String("text") != "",
|
||||||
NoCompress: c.Bool("no-compress"),
|
NoCompress: c.Bool("no-compress"),
|
||||||
|
Overwrite: c.Bool("overwrite"),
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
crocOptions.RelayAddress6 = ""
|
crocOptions.RelayAddress6 = ""
|
||||||
|
@ -388,6 +390,7 @@ func receive(c *cli.Context) (err error) {
|
||||||
RelayPassword: determinePass(c),
|
RelayPassword: determinePass(c),
|
||||||
OnlyLocal: c.Bool("local"),
|
OnlyLocal: c.Bool("local"),
|
||||||
IP: c.String("ip"),
|
IP: c.String("ip"),
|
||||||
|
Overwrite: c.Bool("overwrite"),
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
crocOptions.RelayAddress6 = ""
|
crocOptions.RelayAddress6 = ""
|
||||||
|
|
|
@ -65,6 +65,7 @@ type Options struct {
|
||||||
SendingText bool
|
SendingText bool
|
||||||
NoCompress bool
|
NoCompress bool
|
||||||
IP string
|
IP string
|
||||||
|
Overwrite bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client holds the state of the croc transfer
|
// 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)
|
log.Debugf("%s %+x %+x %+v", fileInfo.Name, fileHash, fileInfo.Hash, errHash)
|
||||||
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
if !bytes.Equal(fileHash, fileInfo.Hash) {
|
||||||
log.Debugf("hashes are not equal %x != %x", 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)))
|
ans := utils.GetInput(fmt.Sprintf("\rOverwrite '%s'? (y/n) ",path.Join(fileInfo.FolderRemote, fileInfo.Name)))
|
||||||
if strings.TrimSpace(strings.ToLower(ans)) != "y" {
|
if strings.TrimSpace(strings.ToLower(ans)) != "y" {
|
||||||
fmt.Fprintf(os.Stderr,"skipping '%s'",path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
fmt.Fprintf(os.Stderr,"skipping '%s'",path.Join(fileInfo.FolderRemote, fileInfo.Name))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue