fix(store): normalise default directory paths
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
a662498891
commit
4581c09631
3 changed files with 24 additions and 7 deletions
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/klauspost/compress/zstd"
|
||||
)
|
||||
|
||||
var defaultArchiveOutputDirectory = ".core/archive"
|
||||
var defaultArchiveOutputDirectory = ".core/archive/"
|
||||
|
||||
// Usage example: `options := store.CompactOptions{Before: time.Now().Add(-90 * 24 * time.Hour), Output: "/tmp/archive", Format: "gzip"}`
|
||||
type CompactOptions struct {
|
||||
|
|
|
|||
13
path_test.go
Normal file
13
path_test.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPath_Normalise_Good_TrailingSlashes(t *testing.T) {
|
||||
assert.Equal(t, ".core/state/scroll-session.duckdb", workspaceFilePath(".core/state/", "scroll-session"))
|
||||
assert.Equal(t, ".core/archive/journal-20260404-010203.jsonl.gz", joinPath(".core/archive/", "journal-20260404-010203.jsonl.gz"))
|
||||
assert.Equal(t, ".core/archive", normaliseDirectoryPath(".core/archive///"))
|
||||
}
|
||||
16
workspace.go
16
workspace.go
|
|
@ -30,7 +30,7 @@ SELECT
|
|||
created_at
|
||||
FROM workspace_entries`
|
||||
|
||||
var defaultWorkspaceStateDirectory = ".core/state"
|
||||
var defaultWorkspaceStateDirectory = ".core/state/"
|
||||
|
||||
// Workspace buffers mutable work-in-progress in `.core/state/scroll-session.duckdb`
|
||||
// until Commit or Discard removes the file.
|
||||
|
|
@ -197,10 +197,7 @@ func discoverOrphanWorkspaces(stateDirectory string, backingStore *Store) []*Wor
|
|||
}
|
||||
|
||||
func normaliseWorkspaceStateDirectory(stateDirectory string) string {
|
||||
for stateDirectory != "" && core.HasSuffix(stateDirectory, "/") {
|
||||
stateDirectory = core.TrimSuffix(stateDirectory, "/")
|
||||
}
|
||||
return stateDirectory
|
||||
return normaliseDirectoryPath(stateDirectory)
|
||||
}
|
||||
|
||||
func workspaceNameFromPath(stateDirectory, databasePath string) string {
|
||||
|
|
@ -514,5 +511,12 @@ func joinPath(base, name string) string {
|
|||
if base == "" {
|
||||
return name
|
||||
}
|
||||
return core.Concat(core.TrimSuffix(base, "/"), "/", name)
|
||||
return core.Concat(normaliseDirectoryPath(base), "/", name)
|
||||
}
|
||||
|
||||
func normaliseDirectoryPath(directory string) string {
|
||||
for directory != "" && core.HasSuffix(directory, "/") {
|
||||
directory = core.TrimSuffix(directory, "/")
|
||||
}
|
||||
return directory
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue