|
|
|
@ -67,14 +67,22 @@ func (s NoteIndexingStats) String() string {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NoteIndexOpts holds the options for the indexing process.
|
|
|
|
|
type NoteIndexOpts struct {
|
|
|
|
|
// When true, existing notes will be reindexed.
|
|
|
|
|
Force bool
|
|
|
|
|
Verbose bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// indexTask indexes the notes in the given directory with the NoteIndex.
|
|
|
|
|
type indexTask struct {
|
|
|
|
|
path string
|
|
|
|
|
config Config
|
|
|
|
|
force bool
|
|
|
|
|
index NoteIndex
|
|
|
|
|
parser NoteParser
|
|
|
|
|
logger util.Logger
|
|
|
|
|
path string
|
|
|
|
|
config Config
|
|
|
|
|
force bool
|
|
|
|
|
verbose bool
|
|
|
|
|
index NoteIndex
|
|
|
|
|
parser NoteParser
|
|
|
|
|
logger util.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexingStats, error) {
|
|
|
|
@ -88,15 +96,35 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
|
|
|
|
|
return stats, wrap(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print := func(message string) {
|
|
|
|
|
if t.verbose {
|
|
|
|
|
fmt.Println(message)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
force := t.force || needsReindexing
|
|
|
|
|
|
|
|
|
|
type IgnoredFile struct {
|
|
|
|
|
Path string
|
|
|
|
|
Reason string
|
|
|
|
|
}
|
|
|
|
|
ignoredFiles := []IgnoredFile{}
|
|
|
|
|
|
|
|
|
|
shouldIgnorePath := func(path string) (bool, error) {
|
|
|
|
|
notifyIgnored := func(reason string) {
|
|
|
|
|
ignoredFiles = append(ignoredFiles, IgnoredFile{
|
|
|
|
|
Path: path,
|
|
|
|
|
Reason: reason,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
group, err := t.config.GroupConfigForPath(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return true, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if filepath.Ext(path) != "."+group.Note.Extension {
|
|
|
|
|
notifyIgnored("expected extension \"" + group.Note.Extension + "\"")
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -106,6 +134,7 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
|
|
|
|
|
return true, errors.Wrapf(err, "failed to match ignore glob %s to %s", ignoreGlob, path)
|
|
|
|
|
}
|
|
|
|
|
if matches {
|
|
|
|
|
notifyIgnored("matched ignore glob \"" + ignoreGlob + "\"")
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -123,6 +152,7 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
|
|
|
|
|
// FIXME: Use the FS?
|
|
|
|
|
count, err := paths.Diff(source, target, force, func(change paths.DiffChange) error {
|
|
|
|
|
callback(change)
|
|
|
|
|
print("- " + change.Kind.String() + " " + change.Path)
|
|
|
|
|
absPath := filepath.Join(t.path, change.Path)
|
|
|
|
|
|
|
|
|
|
switch change.Kind {
|
|
|
|
@ -147,9 +177,14 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
|
|
|
|
|
err := t.index.Remove(change.Path)
|
|
|
|
|
t.logger.Err(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
for _, ignored := range ignoredFiles {
|
|
|
|
|
print("- ignored " + ignored.Path + ": " + ignored.Reason)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stats.SourceCount = count
|
|
|
|
|
stats.Duration = time.Since(startTime)
|
|
|
|
|
|
|
|
|
@ -157,5 +192,6 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
|
|
|
|
|
err = t.index.SetNeedsReindexing(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print("")
|
|
|
|
|
return stats, wrap(err)
|
|
|
|
|
}
|
|
|
|
|