Browse Source

Fix temp file in Edit.go

master
Tovi Jaeschke-Rogers 5 years ago
parent
commit
65ff535b10
2 changed files with 9 additions and 5 deletions
  1. +9
    -5
      Encryption/Edit.go
  2. BIN
      fenc

+ 9
- 5
Encryption/Edit.go View File

@ -26,7 +26,11 @@ func EditEncryptedFile(password string, FilePath string) (error) {
return errors.New("EDITOR variable cannot be blank") return errors.New("EDITOR variable cannot be blank")
} }
tmpFilePath = "/tmp/klsadjhflk"
tmpFilePath = os.Getenv("TMPDIR")
if tmpFilePath == "" {
tmpFilePath = "/tmp"
}
ciphertext, e = ioutil.ReadFile(FilePath) ciphertext, e = ioutil.ReadFile(FilePath)
if e != nil { if e != nil {
return e return e
@ -40,7 +44,7 @@ func EditEncryptedFile(password string, FilePath string) (error) {
return e return e
} }
tmpFile, e = os.Create(tmpFilePath)
tmpFile, e = ioutil.TempFile(tmpFilePath, "")
if e != nil { if e != nil {
return e return e
} }
@ -54,7 +58,7 @@ func EditEncryptedFile(password string, FilePath string) (error) {
return e return e
} }
cmd = exec.Command(editor, tmpFilePath)
cmd = exec.Command(editor, tmpFile.Name())
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
@ -63,7 +67,7 @@ func EditEncryptedFile(password string, FilePath string) (error) {
return e return e
} }
plaintext, e = ioutil.ReadFile(tmpFilePath)
plaintext, e = ioutil.ReadFile(tmpFile.Name())
if e != nil { if e != nil {
return e return e
} }
@ -80,7 +84,7 @@ func EditEncryptedFile(password string, FilePath string) (error) {
defer func() { defer func() {
encryptedFile.Close() encryptedFile.Close()
SecureDelete(tmpFilePath)
SecureDelete(tmpFile.Name())
}() }()
_, e = io.Copy(encryptedFile, bytes.NewReader(ciphertext)) _, e = io.Copy(encryptedFile, bytes.NewReader(ciphertext))


BIN
fenc View File


Loading…
Cancel
Save