diff --git a/storage/history.go b/storage/history.go index e78a844..53733c4 100644 --- a/storage/history.go +++ b/storage/history.go @@ -20,6 +20,8 @@ var ( ) var ( + historyFileName = "history" + invalidHistoryItemErr = "invalid history item: %s" ) @@ -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) { diff --git a/storage/measurements.go b/storage/measurements.go index 05e5aa4..780cb3f 100644 --- a/storage/measurements.go +++ b/storage/measurements.go @@ -18,6 +18,8 @@ var ( ) var ( + measurementsFileName = "measurements" + saveIdToSessionErr = "failed to save measurement ID: %s" readMeasuremetsErr = "failed to read previous measurements: %s" ) @@ -91,5 +93,5 @@ func (s *LocalStorage) GetMeasurements() ([]byte, error) { } func (s *LocalStorage) measurementsPath() string { - return s.joinSessionDir("measurements") + return s.joinSessionDir(measurementsFileName) } diff --git a/storage/migrations.go b/storage/migrations.go index 50b30c6..cdafc79 100644 --- a/storage/migrations.go +++ b/storage/migrations.go @@ -1,6 +1,7 @@ package storage import ( + "fmt" "os" "path/filepath" "strings" @@ -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) @@ -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 }