Skip to content

Commit

Permalink
don't error out when the log file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
quackduck committed Jun 18, 2022
1 parent 8ecaaf1 commit 8817cb6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -254,7 +253,13 @@ func getLogFile() map[string]string {
return logFile
}
ensureTrashDir()
b, err := ioutil.ReadFile(dataDir + "/" + logFileName)
b, err := os.ReadFile(dataDir + "/" + logFileName)
if os.IsNotExist(err) {
return make(map[string]string)
}
if err != nil {
handleErr(err)
}
lines := make(map[string]string)
err = json.Unmarshal(b, &lines)
if err != nil {
Expand All @@ -271,7 +276,7 @@ func setLogFile(m map[string]string) {
handleErr(err)
return
}
err = ioutil.WriteFile(dataDir+"/"+logFileName, b, 0644)
err = os.WriteFile(dataDir+"/"+logFileName, b, 0644)
if err != nil {
handleErr(err)
}
Expand Down

0 comments on commit 8817cb6

Please sign in to comment.