fix: uneeded func + uneeded bogus note creation logic
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
// "donniemarko/internal/note"
|
||||
)
|
||||
|
||||
type ChangeType int
|
||||
@ -50,28 +49,6 @@ func (s *ScannerService) SetHandler(handler ChangeHandler) {
|
||||
s.handler = handler
|
||||
}
|
||||
|
||||
func (s *ScannerService) FindAll() ([]string, error) {
|
||||
var notePath []string
|
||||
err := filepath.Walk(s.RootDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// skip the root dir itself
|
||||
if s.RootDir == path {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !isValidNoteFile(path, info) {
|
||||
return nil
|
||||
}
|
||||
|
||||
notePath = append(notePath, path)
|
||||
return nil
|
||||
})
|
||||
return notePath, err
|
||||
}
|
||||
|
||||
// Scan walks the root folder and update the states of each notes if
|
||||
// it has changed since the last time a scan occured
|
||||
func (s *ScannerService) Scan() ([]Change, error) {
|
||||
@ -85,7 +62,8 @@ func (s *ScannerService) Scan() ([]Change, error) {
|
||||
if s.RootDir == path {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// ignore anything that isn't a note
|
||||
if !isValidNoteFile(path, info) {
|
||||
return nil
|
||||
}
|
||||
@ -95,7 +73,7 @@ func (s *ScannerService) Scan() ([]Change, error) {
|
||||
lastMod, existed := s.LastStates[path]
|
||||
if !existed {
|
||||
// create the note if it didn't exist yet
|
||||
s.handler.HandleCreate(path)
|
||||
// s.handler.HandleCreate(path)
|
||||
changes = append(changes, Change{Type: Created, Path: path, ModTime: lastMod})
|
||||
} else if info.ModTime().After(lastMod) {
|
||||
changes = append(changes, Change{Type: Modified, Path: path, ModTime: info.ModTime()})
|
||||
@ -115,8 +93,7 @@ func (s *ScannerService) Scan() ([]Change, error) {
|
||||
return changes, nil
|
||||
}
|
||||
|
||||
// Monitor rescan the root folder at each new tick and handle state
|
||||
// modification
|
||||
// Monitor rescan the root folder at each new tick and handle state modifications
|
||||
func (s *ScannerService) Monitor(ctx context.Context) error {
|
||||
ticker := time.NewTicker(s.Interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
Reference in New Issue
Block a user