Skip to content

Commit

Permalink
fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
radulucut committed Oct 31, 2024
1 parent 9368fa6 commit 6539f76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion storage/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var (
)

var (
historyFileName = "history"

invalidHistoryItemErr = "invalid history item: %s"
)

Expand Down Expand Up @@ -142,7 +144,7 @@ func (s *LocalStorage) SaveCommandToHistory(
}

func (s *LocalStorage) historyPath() string {
return s.joinSessionDir("history")
return s.joinSessionDir(historyFileName)
}

func parseHistoryItem(line string) (string, error) {
Expand Down
4 changes: 3 additions & 1 deletion storage/measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var (
)

var (
measurementsFileName = "measurements"

saveIdToSessionErr = "failed to save measurement ID: %s"
readMeasuremetsErr = "failed to read previous measurements: %s"
)
Expand Down Expand Up @@ -91,5 +93,5 @@ func (s *LocalStorage) GetMeasurements() ([]byte, error) {
}

func (s *LocalStorage) measurementsPath() string {
return s.joinSessionDir("measurements")
return s.joinSessionDir(measurementsFileName)
}
13 changes: 11 additions & 2 deletions storage/migrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -19,7 +20,7 @@ func (s *LocalStorage) Migrate() error {
for i := s.config.LastMigration; i < len(migrations); i++ {
err := migrations[i]()
if err != nil {
return err
fmt.Printf("Warning: migration %d failed: %v", i, err)
}
}
s.config.LastMigration = len(migrations)
Expand All @@ -42,7 +43,15 @@ func (s *LocalStorage) UpdateSessionDir() error {
}
parts := strings.Split(name, "_")
newName := parts[2] + "_" + parts[1]
err := os.Rename(filepath.Join(oldDir, name), filepath.Join(s.sessionsDir, newName))
err := os.Rename(filepath.Join(oldDir, name, "measurements"), filepath.Join(s.sessionsDir, newName, measurementsFileName))
if err != nil {
return err
}
err = os.Rename(filepath.Join(oldDir, name, "history"), filepath.Join(s.sessionsDir, newName, historyFileName))
if err != nil {
return err
}
err = os.RemoveAll(filepath.Join(oldDir, name))
if err != nil {
return err
}
Expand Down

0 comments on commit 6539f76

Please sign in to comment.