From df644345fb1e6d4dfd04e973a542c99d9ebac761 Mon Sep 17 00:00:00 2001 From: AccursedGalaxy Date: Fri, 8 Nov 2024 21:19:19 +0100 Subject: [PATCH] fix: Directory Not Found Error - Now only shows warning and skips the directory --- TODO.md | 7 ++++++- scan/scan.go | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index d2e35c3..c39f9fb 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,11 @@ ## Fixes -- [ ] When there is a directory listed to scan, but it doesn't exist, there is a error and no output is generated. +- [X] When there is a directory listed to scan, but it doesn't exist, there is a error and no output is generated. -> I should add a check to see if the directory exists before trying to scan it. -> And just warn the user that the directory doesn't exist or is not accessible. + +- [ ] Implement some sort of check for this: + -> Before just loading data from cache, check if there is a new directory setup in the config/or a directory where we do not have any data. + -> If there is none just move on to laod from cache and display output normall. + -> If there is a new directory or a directory where we do not have any data for, then fetch data and update cache. \ No newline at end of file diff --git a/scan/scan.go b/scan/scan.go index 8539fb3..0150c82 100644 --- a/scan/scan.go +++ b/scan/scan.go @@ -74,6 +74,15 @@ func fetchRepoMeta(repoPath, author string) RepoMetadata { Path: repoPath, LastAnalyzed: time.Now(), } + + // Check if directory exists and is accessible + if _, err := os.Stat(repoPath); os.IsNotExist(err) { + fmt.Printf("Warning: Directory not found: %s\n", repoPath) + return meta + } else if err != nil { + fmt.Printf("Warning: Cannot access directory: %s - %v\n", repoPath, err) + return meta + } // Get commit dates in a single git command authorCmd := exec.Command("git", "-C", repoPath, "log", "--all", @@ -210,11 +219,14 @@ func fetchDetailedCommitInfo(repoPath string, author string, since time.Time) ([ // ScanDirectories - scans for Git repositories in the specified directories func ScanDirectories(dirs []string, author string, shouldExclude func(string) bool) ([]RepoMetadata, error) { var repos []RepoMetadata + var skippedDirs []string for _, dir := range dirs { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + // Handle directory access errors gracefully if err != nil { - return err + skippedDirs = append(skippedDirs, dir) + return filepath.SkipDir } if info == nil { return nil @@ -233,8 +245,19 @@ func ScanDirectories(dirs []string, author string, shouldExclude func(string) bo } return nil }) + + // Handle initial directory access error if err != nil { - return nil, fmt.Errorf("error walking directory %s: %v", dir, err) + skippedDirs = append(skippedDirs, dir) + continue // Skip to next directory instead of returning error + } + } + + // Print warnings for skipped directories + if len(skippedDirs) > 0 { + fmt.Println("\nWarning: The following directories were skipped due to access issues:") + for _, dir := range skippedDirs { + fmt.Printf("- %s\n", dir) } }