mirror of https://github.com/schollz/croc.git
Merge pull request #23 from techtide/master
Quits program if a file already exists.
This commit is contained in:
commit
bf9021c925
16
connect.go
16
connect.go
|
@ -208,9 +208,16 @@ func (c *Connection) runClient() {
|
||||||
// have the main thread ask for the okay
|
// have the main thread ask for the okay
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
fmt.Printf("Receiving file (%d bytes) into: %s\n", c.File.Size, c.File.Name)
|
fmt.Printf("Receiving file (%d bytes) into: %s\n", c.File.Size, c.File.Name)
|
||||||
|
var sentFileNames []string
|
||||||
|
|
||||||
|
if fileAlreadyExists(sentFileNames, c.File.Name) {
|
||||||
|
fmt.Printf("Will not overwrite file!")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
getOK := getInput("ok? (y/n): ")
|
getOK := getInput("ok? (y/n): ")
|
||||||
if getOK == "y" {
|
if getOK == "y" {
|
||||||
gotOK = true
|
gotOK = true
|
||||||
|
sentFileNames = append(sentFileNames, c.File.Name)
|
||||||
}
|
}
|
||||||
gotResponse = true
|
gotResponse = true
|
||||||
}
|
}
|
||||||
|
@ -274,6 +281,15 @@ func (c *Connection) runClient() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fileAlreadyExists(s []string, f string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == f {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Connection) catFile(fname string) {
|
func (c *Connection) catFile(fname string) {
|
||||||
// cat the file
|
// cat the file
|
||||||
os.Remove(fname)
|
os.Remove(fname)
|
||||||
|
|
Loading…
Reference in New Issue