mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Added flag for unencrypted files
This commit is contained in:
parent
6b9cc84313
commit
9c6d672272
1 changed files with 21 additions and 10 deletions
13
connect.go
13
connect.go
|
@ -42,6 +42,7 @@ type FileMetaData struct {
|
|||
Hash string
|
||||
Path string
|
||||
IsDir bool
|
||||
IsEncrypted bool
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -153,16 +154,20 @@ func (c *Connection) Run() error {
|
|||
if c.DontEncrypt {
|
||||
// don't encrypt
|
||||
CopyFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc")
|
||||
c.File.IsEncrypted = false
|
||||
} else {
|
||||
// encrypt
|
||||
log.Debug("encrypting...")
|
||||
if err := EncryptFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc", c.Code); err != nil {
|
||||
return err
|
||||
}
|
||||
c.File.IsEncrypted = true
|
||||
}
|
||||
// split file into pieces to send
|
||||
if err := SplitFile(c.File.Name+".enc", c.NumberOfConnections); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// get file hash
|
||||
var err error
|
||||
c.File.Hash, err = HashFile(path.Join(c.File.Path, c.File.Name))
|
||||
|
@ -381,9 +386,15 @@ func (c *Connection) runClient() error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
if c.File.IsEncrypted {
|
||||
if err := DecryptFile(path.Join(c.Path, c.File.Name+".enc"), path.Join(c.Path, c.File.Name), c.Code); err != nil {
|
||||
return errors.Wrap(err, "Problem decrypting file")
|
||||
}
|
||||
} else {
|
||||
if err := CopyFile(path.Join(c.Path, c.File.Name+".enc"), path.Join(c.Path, c.File.Name)); err != nil {
|
||||
return errors.Wrap(err, "Problem copying file")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !c.Debug {
|
||||
os.Remove(path.Join(c.Path, c.File.Name+".enc"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue