Skip to content

Commit

Permalink
fix: Directory Not Found Error - Now only shows warning and skips the…
Browse files Browse the repository at this point in the history
… directory
  • Loading branch information
AccursedGalaxy committed Nov 8, 2024
1 parent 2dcdad4 commit df64434
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
27 changes: 25 additions & 2 deletions scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down

0 comments on commit df64434

Please sign in to comment.