diff --git a/core/handlers/vault/initialize_handler.go b/core/handlers/vault/initialize_handler.go index ac75b4e..7be6f3c 100644 --- a/core/handlers/vault/initialize_handler.go +++ b/core/handlers/vault/initialize_handler.go @@ -11,9 +11,11 @@ import ( ) type initializeCommand struct { - VaultName string `json:"vaultName"` - VaultPath string `json:"vaultPath"` - TemplateDirectory string `json:"templateDirectory"` + VaultName string `json:"vaultName"` + VaultPath string `json:"vaultPath"` + TemplateDirectory string `json:"templateDirectory"` + ExcludeIndexFiles []string `json:"excludeIndexFiles"` + OverrideDefaultIgnores bool `json:"overrideDefaultIgnores"` } type InitializeHandler struct { @@ -32,7 +34,12 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any return nil, err } - store := store.NewVaultStore(cmd.VaultName, cmd.VaultPath, cmd.TemplateDirectory) + store := store.NewVaultStore( + cmd.VaultName, + cmd.VaultPath, + cmd.TemplateDirectory, + cmd.ExcludeIndexFiles, + cmd.OverrideDefaultIgnores) err := persistence.InitializeDBContext(store.Config.VaultName()) if err != nil { diff --git a/core/services/index_rebuilder.go b/core/services/index_rebuilder.go index a3939e3..e810b91 100644 --- a/core/services/index_rebuilder.go +++ b/core/services/index_rebuilder.go @@ -8,10 +8,11 @@ import ( "slices" "strings" - filehandling "github.com/KristianJBorgwarth/dendrite.daemon/core/file_handling" + "github.com/KristianJBorgwarth/dendrite.daemon/core/file_handling" "github.com/KristianJBorgwarth/dendrite.daemon/core/models" "github.com/KristianJBorgwarth/dendrite.daemon/persistence" "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories" + "github.com/KristianJBorgwarth/dendrite.daemon/persistence/store" ) type IIndexRebuilder interface { @@ -136,7 +137,7 @@ func (r *indexRebuilder) readFiles(vault string) ([]*filehandling.File, error) { } func (r *indexRebuilder) IsValidDirectory(path string) bool { - ignoredDirs := []string{".git", ".templates", "temp"} + ignoredDirs := store.GetVaultStore().GetExcludeIndexFiles() for part := range strings.SplitSeq(path, string(filepath.Separator)) { if slices.Contains(ignoredDirs, part) { return false diff --git a/dendrite b/dendrite index 73a4b73..0e49273 100755 Binary files a/dendrite and b/dendrite differ diff --git a/persistence/config/vault_configuration.go b/persistence/config/vault_configuration.go index 6d1df17..0d3e031 100644 --- a/persistence/config/vault_configuration.go +++ b/persistence/config/vault_configuration.go @@ -1,13 +1,28 @@ package persistenceconfig type VaultConfiguration struct { - name string - path string - templateDirectory string + name string + path string + templateDirectory string + exludeIndexFiles []string + defaultExcludes []string + overrideDefaultIgnores bool } -func NewVaultConfiguration(vaultName, vaultPath, templateDirectory string) *VaultConfiguration { - return &VaultConfiguration{name: vaultName, path: vaultPath, templateDirectory: templateDirectory} +func NewVaultConfiguration( + vaultName, + vaultPath, + templateDirectory string, + excludeIndexFiles []string, + overrideDefaultIgnores bool, +) *VaultConfiguration { + return &VaultConfiguration{ + name: vaultName, + path: vaultPath, + templateDirectory: templateDirectory, + exludeIndexFiles: excludeIndexFiles, + defaultExcludes: []string{".git", ".templates"}, + } } func (vc *VaultConfiguration) VaultName() string { @@ -21,3 +36,15 @@ func (vc *VaultConfiguration) VaultPath() string { func (vc *VaultConfiguration) TemplateDirectory() string { return vc.templateDirectory } + +func (vc *VaultConfiguration) ExcludeIndexFiles() []string { + return vc.exludeIndexFiles +} + +func (vc *VaultConfiguration) GetExcludeIndexFiles() []string { + defaultIgnores := []string{".git", ".templates"} + if vc.overrideDefaultIgnores { + return vc.exludeIndexFiles + } + return append(defaultIgnores, vc.exludeIndexFiles...) +} diff --git a/persistence/store/vault_store.go b/persistence/store/vault_store.go index d557a5a..ef82e20 100644 --- a/persistence/store/vault_store.go +++ b/persistence/store/vault_store.go @@ -12,11 +12,23 @@ type VaultStore struct { var vaultStore *VaultStore -func NewVaultStore(vaultName, vaultPath, templateDir string) *VaultStore { +func NewVaultStore( + vaultName, + vaultPath, + templateDir string, + exludeIndexFiles []string, + overrideDefaultIgnores bool, +) *VaultStore { if vaultStore != nil { return vaultStore } - vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(vaultName, vaultPath, templateDir)} + vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration( + vaultName, + vaultPath, + templateDir, + exludeIndexFiles, + overrideDefaultIgnores, + )} return vaultStore } @@ -44,3 +56,6 @@ func (vs *VaultStore) fileTypeCheck(templateName string) string { return templateName } +func (vs *VaultStore) GetExcludeIndexFiles() []string { + return vs.Config.GetExcludeIndexFiles() +} diff --git a/test/test_integration/main_test.go b/test/test_integration/main_test.go index 77553a6..c7455bd 100644 --- a/test/test_integration/main_test.go +++ b/test/test_integration/main_test.go @@ -46,7 +46,7 @@ func NewDBFixture() *DBFixture { DB: dbContext.DB, DBPath: dbPath, TestContext: context.Background(), - VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates")), + VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates"), []string{}, false), } }