Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
No need to create dirs ahead of time, when persist does it as well.
Maybe this could go into a separate PR.
Also comment in NewPersistentDB that we keep doing it to have an early error
instead of user only getting one on first collection creation.
  • Loading branch information
philippgille committed Mar 21, 2024
1 parent e1d641b commit ce95d9e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
8 changes: 1 addition & 7 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"slices"
"sync"
Expand Down Expand Up @@ -48,11 +47,6 @@ func newCollection(name string, metadata map[string]string, embed EmbeddingFunc,
if dbDir != "" {
safeName := hash2hex(name)
c.persistDirectory = filepath.Join(dbDir, safeName)
// Create dir
err := os.MkdirAll(c.persistDirectory, 0o700)
if err != nil {
return nil, fmt.Errorf("couldn't create collection directory: %w", err)
}
// Persist name and metadata
metadataPath := filepath.Join(c.persistDirectory, metadataFileName)
metadataPath += ".gob"
Expand All @@ -63,7 +57,7 @@ func newCollection(name string, metadata map[string]string, embed EmbeddingFunc,
Name: name,
Metadata: m,
}
err = persist(metadataPath, pc, false, "")
err := persist(metadataPath, pc, false, "")
if err != nil {
return nil, fmt.Errorf("couldn't persist collection metadata: %w", err)
}
Expand Down
9 changes: 1 addition & 8 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,6 @@ func (db *DB) Export(filePath string, compress bool, encryptionKey string) error
}
}

// Create parent dir if it doesn't exist
parentDir := filepath.Dir(filePath)
err := os.MkdirAll(parentDir, 0o700)
if err != nil {
return fmt.Errorf("couldn't create parent directory: %w", err)
}

// Create persistence structs with exported fields so that they can be encoded
// as gob.
type persistenceCollection struct {
Expand All @@ -282,7 +275,7 @@ func (db *DB) Export(filePath string, compress bool, encryptionKey string) error
}
}

err = persist(filePath, persistenceDB, compress, encryptionKey)
err := persist(filePath, persistenceDB, compress, encryptionKey)
if err != nil {
return fmt.Errorf("couldn't export DB: %w", err)
}
Expand Down

0 comments on commit ce95d9e

Please sign in to comment.