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
31
connect.go
31
connect.go
|
@ -37,11 +37,12 @@ type Connection struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileMetaData struct {
|
type FileMetaData struct {
|
||||||
Name string
|
Name string
|
||||||
Size int
|
Size int
|
||||||
Hash string
|
Hash string
|
||||||
Path string
|
Path string
|
||||||
IsDir bool
|
IsDir bool
|
||||||
|
IsEncrypted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -153,16 +154,20 @@ func (c *Connection) Run() error {
|
||||||
if c.DontEncrypt {
|
if c.DontEncrypt {
|
||||||
// don't encrypt
|
// don't encrypt
|
||||||
CopyFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc")
|
CopyFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc")
|
||||||
|
c.File.IsEncrypted = false
|
||||||
} else {
|
} else {
|
||||||
// encrypt
|
// encrypt
|
||||||
log.Debug("encrypting...")
|
log.Debug("encrypting...")
|
||||||
if err := EncryptFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc", c.Code); err != nil {
|
if err := EncryptFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc", c.Code); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := SplitFile(c.File.Name+".enc", c.NumberOfConnections); err != nil {
|
c.File.IsEncrypted = true
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// split file into pieces to send
|
||||||
|
if err := SplitFile(c.File.Name+".enc", c.NumberOfConnections); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// get file hash
|
// get file hash
|
||||||
var err error
|
var err error
|
||||||
c.File.Hash, err = HashFile(path.Join(c.File.Path, c.File.Name))
|
c.File.Hash, err = HashFile(path.Join(c.File.Path, c.File.Name))
|
||||||
|
@ -381,8 +386,14 @@ func (c *Connection) runClient() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := DecryptFile(path.Join(c.Path, c.File.Name+".enc"), path.Join(c.Path, c.File.Name), c.Code); err != nil {
|
if c.File.IsEncrypted {
|
||||||
return errors.Wrap(err, "Problem decrypting file")
|
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 {
|
if !c.Debug {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue