From e6923fa4f5b0a332afdc33b3c00031469b52b560 Mon Sep 17 00:00:00 2001 From: adminoo Date: Sun, 1 Feb 2026 18:26:59 +0100 Subject: [PATCH] fix: uneeded func + uneeded bogus note creation logic --- internal/scanner/scanner.go | 31 ++++--------------------------- internal/scanner/scanner_test.go | 30 ------------------------------ 2 files changed, 4 insertions(+), 57 deletions(-) diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index 84c753b..35de5eb 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -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() diff --git a/internal/scanner/scanner_test.go b/internal/scanner/scanner_test.go index 4b72a36..bf15096 100644 --- a/internal/scanner/scanner_test.go +++ b/internal/scanner/scanner_test.go @@ -7,36 +7,6 @@ import ( "time" ) -func TestScanner_FindMarkdownFiles(t *testing.T) { - tmpDir := t.TempDir() - - files := map[string]string{ - "note1.md": "# Note 1", - "note2.markdown": "# Note 2", - "folder/note3.md": "# Note 3", - "folder/nested/note4.md": "# Note 4", - "readme.txt": "not markdown", - } - - for path, content := range files { - fullPath := filepath.Join(tmpDir, path) - os.MkdirAll(filepath.Dir(fullPath), 0755) - os.WriteFile(fullPath, []byte(content), 0644) - } - - scanner := NewScanner(tmpDir) - found, err := scanner.FindAll() - - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - - // Should only return markdown files - if len(found) != 3 { - t.Errorf("expected 4 files, got %d", len(found)) - } -} - func TestScanner_DetectsNewFile(t *testing.T) { tmpDir := t.TempDir() scanner := NewScanner(tmpDir)