Skip to content

Commit 660ca6f

Browse files
committed
Update go file index.
1 parent b3cb131 commit 660ca6f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

dse/clib/collections/vector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ typedef struct Vector {
3333
static __inline__ int __vector_resize(Vector* v, size_t hint)
3434
{
3535
if (v == NULL) return -EINVAL;
36+
if (v->item_size == 0) return -EINVAL;
3637
if (hint == 0) {
3738
free(v->items);
3839
v->items = NULL;
@@ -76,6 +77,7 @@ static __inline__ size_t vector_len(Vector* v)
7677
static __inline__ int vector_push(Vector* v, void* item)
7778
{
7879
if (v == NULL) return -EINVAL;
80+
if (v->item_size == 0) return -EINVAL;
7981
if (v->capacity == 0) {
8082
__vector_resize(v, v->initial_capacity);
8183
} else if (v->length == v->capacity) {

extra/go/file/index/index.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ func (index *YamlFileIndex) Add(file string) error {
6161

6262
func (index *YamlFileIndex) Scan(path string) {
6363
// Collect the list of yaml files within path.
64-
files := []string{}
6564
file_exts := []string{".yml", ".yaml"}
66-
for _, ext := range file_exts {
67-
indexed_files, _ := indexFiles(path, ext)
68-
files = append(files, indexed_files...)
69-
}
65+
files, _ := indexFiles(path, file_exts)
7066

7167
// Load each file into the index.
7268
for _, f := range files {
@@ -133,16 +129,27 @@ func (index *YamlFileIndex) SaveAll() error {
133129
return nil
134130
}
135131

136-
func indexFiles(path string, extension string) ([]string, error) {
132+
func indexFiles(path string, extensions []string) ([]string, error) {
137133
files := []string{}
138134
fileSystem := os.DirFS(path)
135+
extMap := make(map[string]bool)
136+
for _, ext := range extensions {
137+
extMap[ext] = true
138+
}
139+
139140
err := fs.WalkDir(fileSystem, ".", func(s string, d fs.DirEntry, e error) error {
140141
if e != nil {
141142
return nil
142143
}
143-
slog.Debug(fmt.Sprintf("IndexFiles: %s (%t, %s)", s, d.IsDir(), filepath.Ext(s)))
144-
if !d.IsDir() && filepath.Ext(s) == extension {
144+
if !d.IsDir() && extMap[filepath.Ext(s)] {
145+
slog.Debug(fmt.Sprintf("IndexFiles: %s (indexed, %s)", s, filepath.Ext(s)))
145146
files = append(files, filepath.Join(path, s))
147+
} else {
148+
if d.IsDir() {
149+
slog.Debug(fmt.Sprintf("IndexFiles: %s (directory)", s))
150+
} else {
151+
slog.Debug(fmt.Sprintf("IndexFiles: %s (<not indexed>)", s))
152+
}
146153
}
147154
return nil
148155
})

0 commit comments

Comments
 (0)