mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-02 23:27:22 -04:00
Handle error in writeToStdin; remove unused function removeFile
This commit is contained in:
@@ -53,10 +53,17 @@ func WriteEntry(targetLocation string, entryData []string) {
|
|||||||
|
|
||||||
// writeToStdin writes a string to a command's stdin
|
// writeToStdin writes a string to a command's stdin
|
||||||
func writeToStdin(cmd *exec.Cmd, input string) {
|
func writeToStdin(cmd *exec.Cmd, input string) {
|
||||||
stdin, _ := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(AnsiError + "Failed to access stdin for system command: " + err.Error() + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer stdin.Close()
|
defer func(stdin io.WriteCloser) {
|
||||||
io.WriteString(stdin, input)
|
_ = stdin.Close() // error ignored; if stdin could be accessed, it can probably be closed
|
||||||
|
}(stdin)
|
||||||
|
_, _ = io.WriteString(stdin, input)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,18 +77,6 @@ func CreateTempFile() *os.File {
|
|||||||
return tempFile
|
return tempFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeFile removes a file at targetLocation and does not error if the file does not exist
|
|
||||||
func removeFile(targetLocation string) {
|
|
||||||
// remove existing config file
|
|
||||||
err := os.Remove(targetLocation)
|
|
||||||
if err != nil {
|
|
||||||
// ignore error if file does not exist
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
fmt.Println(AnsiError + "Failed to remove \"" + targetLocation + "\":" + err.Error() + AnsiReset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveTrailingEmptyStrings removes empty strings from the end of a slice
|
// RemoveTrailingEmptyStrings removes empty strings from the end of a slice
|
||||||
func RemoveTrailingEmptyStrings(slice []string) []string {
|
func RemoveTrailingEmptyStrings(slice []string) []string {
|
||||||
for i := len(slice) - 1; i >= 0; i-- {
|
for i := len(slice) - 1; i >= 0; i-- {
|
||||||
|
|||||||
Reference in New Issue
Block a user