Skip to content

Commit

Permalink
avoid renaming backup files and fixing bug in askForConfirmation in w…
Browse files Browse the repository at this point in the history
…indows (newline chars)
  • Loading branch information
pedroangelini committed Feb 18, 2024
1 parent 3dea115 commit 7e53782
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command {
}

func askForConfirmation(msg string) bool {
reader := bufio.NewReader(os.Stdin)
scanner := bufio.NewScanner(os.Stdin)
fmt.Fprint(os.Stderr, msg)
s, _ := reader.ReadString('\n')
s = strings.TrimSuffix(s, "\n")
scanner.Scan()
s := scanner.Text()
s = strings.ToLower(s)

return s == "y"
Expand Down
10 changes: 3 additions & 7 deletions core/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ func (t *Timetrace) DeleteRecordsByProject(key string) error {
}

// EditRecordManual opens the record file in the preferred or default editor.
// note we don't rename the backup, because it could have inconsistency between
// start time and file name
func (t *Timetrace) EditRecordManual(recordTime time.Time) error {
path := t.fs.RecordFilepath(recordTime)
backupPath := t.fs.RecordBackupFilepath(recordTime)

rec, err := t.loadRecord(path)
if err != nil {
Expand Down Expand Up @@ -282,13 +283,8 @@ func (t *Timetrace) EditRecordManual(recordTime time.Time) error {
}

newPath := t.fs.RecordFilepath(newStart)
newBackupPath := t.fs.RecordBackupFilepath(newStart)

if err = os.Rename(path, newPath); err != nil {
return err
}

return os.Rename(backupPath, newBackupPath)
return os.Rename(path, newPath)
}

// EditRecord loads the record internally, applies the option values and saves the record
Expand Down

0 comments on commit 7e53782

Please sign in to comment.