mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-03 15:47:23 -04:00
Properly close files to fix various issues on Windows (fixes GPG keygen, note temp files not being deleted)
This commit is contained in:
+8
-3
@@ -102,6 +102,9 @@ func editNote(baseNote []string) ([]string, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// close tempFile
|
||||||
|
tempFile.Close()
|
||||||
|
|
||||||
// edit the tempFile (note) with the user's text editor
|
// edit the tempFile (note) with the user's text editor
|
||||||
cmd := exec.Command(editor, tempFile.Name())
|
cmd := exec.Command(editor, tempFile.Name())
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -114,20 +117,22 @@ func editNote(baseNote []string) ([]string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// open the tempFile for reading
|
// open the tempFile for reading
|
||||||
file, err := os.Open(tempFile.Name())
|
tempFile, err = os.Open(tempFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(offline.AnsiError + "Failed to open temporary file (\"" + tempFile.Name() + "\") " + err.Error() + offline.AnsiReset)
|
fmt.Println(offline.AnsiError + "Failed to open temporary file (\"" + tempFile.Name() + "\") " + err.Error() + offline.AnsiReset)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
// read the edited note from the tempFile
|
// read the edited note from the tempFile
|
||||||
var note []string
|
var note []string
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(tempFile)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
note = append(note, scanner.Text())
|
note = append(note, scanner.Text())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// close the tempFile
|
||||||
|
tempFile.Close()
|
||||||
|
|
||||||
// return the edited note if it is different from baseNote
|
// return the edited note if it is different from baseNote
|
||||||
if !reflect.DeepEqual(offline.RemoveTrailingEmptyStrings(note), baseNote) {
|
if !reflect.DeepEqual(offline.RemoveTrailingEmptyStrings(note), baseNote) {
|
||||||
return note, true
|
return note, true
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ func GpgKeyGen() string {
|
|||||||
unixTime := strconv.FormatInt(time.Now().Unix(), 10)
|
unixTime := strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
gpgGenTempFile.WriteString(strings.Join([]string{"Key-Type: eddsa", "Key-Curve: ed25519", "Key-Usage: sign", "Subkey-Type: ecdh", "Subkey-Curve: cv25519", "Subkey-Usage: encrypt", "Name-Real: libmutton-" + unixTime, "Name-Comment: gpg-libmutton", "Name-Email: github.com/rwinkhart/libmutton", "Expire-Date: 0"}, "\n"))
|
gpgGenTempFile.WriteString(strings.Join([]string{"Key-Type: eddsa", "Key-Curve: ed25519", "Key-Usage: sign", "Subkey-Type: ecdh", "Subkey-Curve: cv25519", "Subkey-Usage: encrypt", "Name-Real: libmutton-" + unixTime, "Name-Comment: gpg-libmutton", "Name-Email: github.com/rwinkhart/libmutton", "Expire-Date: 0"}, "\n"))
|
||||||
|
|
||||||
|
// close gpg-gen file
|
||||||
|
gpgGenTempFile.Close()
|
||||||
|
|
||||||
// generate GPG key based on gpg-gen file
|
// generate GPG key based on gpg-gen file
|
||||||
cmd := exec.Command("gpg", "-q", "--batch", "--generate-key", gpgGenTempFile.Name())
|
cmd := exec.Command("gpg", "-q", "--batch", "--generate-key", gpgGenTempFile.Name())
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
|||||||
Reference in New Issue
Block a user