Skip to content

Commit 06e6ff1

Browse files
committed
count and report number of failed directories, consider failed directories for exit code
1 parent 773e1c3 commit 06e6ff1

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

scraper.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func (s *Scraper) Done() bool {
8686
}
8787

8888
//Next scrapes the next directory.
89-
func (s *Scraper) Next() []File {
89+
func (s *Scraper) Next() (files []File, countAsFailed bool) {
9090
if s.Done() {
91-
return nil
91+
return nil, false
9292
}
9393

9494
//fetch next directory from stack, list its entries
@@ -100,15 +100,14 @@ func (s *Scraper) Next() []File {
100100
if err != nil {
101101
if directory.RetryCounter >= 2 {
102102
Log(LogError, "giving up on %s: %s", err.Location, err.Message)
103-
} else {
104-
Log(LogError, "skipping %s for now: %s", err.Location, err.Message)
105-
directory.RetryCounter++
106-
s.Stack = s.Stack.PushBack(directory)
103+
return nil, true
107104
}
108-
return nil
105+
Log(LogError, "skipping %s for now: %s", err.Location, err.Message)
106+
directory.RetryCounter++
107+
s.Stack = s.Stack.PushBack(directory)
108+
return nil, false
109109
}
110110

111-
var files []File
112111
for _, entryName := range entries {
113112
pathForMatching := filepath.Join(directory.Path, entryName)
114113
if strings.HasSuffix(entryName, "/") {
@@ -148,7 +147,7 @@ func (s *Scraper) Next() []File {
148147
}
149148
}
150149

151-
return files
150+
return files, false
152151
}
153152

154153
//matches scheme prefix (e.g. "http:" or "git+ssh:") at the start of a full URL

threads.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type SharedState struct {
3838
//main thread after waiting on the writing thread), so no additional
3939
//locking is required for these fields
4040
DirectoriesScanned uint64
41+
DirectoriesFailed uint64
4142
FilesFound uint64
4243
FilesFailed uint64
4344
FilesTransferred uint64
@@ -73,7 +74,7 @@ func Run(state *SharedState) (exitCode int) {
7374
Gauge("last_run.files_found", int64(state.FilesFound), 1.0)
7475
Gauge("last_run.files_transfered", int64(state.FilesTransferred), 1.0)
7576
Gauge("last_run.files_failed", int64(state.FilesFailed), 1.0)
76-
if state.FilesFailed > 0 {
77+
if state.FilesFailed > 0 || state.DirectoriesFailed > 0 {
7778
Gauge("last_run.success", 0, 1.0)
7879
exitCode = 1
7980
} else {
@@ -82,9 +83,11 @@ func Run(state *SharedState) (exitCode int) {
8283
}
8384

8485
//report results
85-
Log(LogInfo, "%d dirs scanned, %d files found, %d transferred, %d failed",
86-
state.DirectoriesScanned, state.FilesFound,
87-
state.FilesTransferred, state.FilesFailed,
86+
Log(LogInfo, "%d dirs scanned, %d failed",
87+
state.DirectoriesScanned, state.DirectoriesFailed,
88+
)
89+
Log(LogInfo, "%d files found, %d transferred, %d failed",
90+
state.FilesFound, state.FilesTransferred, state.FilesFailed,
8891
)
8992

9093
return
@@ -100,6 +103,7 @@ func makeScraperThread(state *SharedState) <-chan File {
100103
defer state.WaitGroup.Done()
101104
defer close(out)
102105

106+
var directoriesFailed uint64
103107
var directoriesScanned uint64
104108
var filesFound uint64
105109

@@ -112,14 +116,19 @@ func makeScraperThread(state *SharedState) <-chan File {
112116
break
113117
}
114118

115-
for _, file := range scraper.Next() {
119+
files, countAsFailed := scraper.Next()
120+
for _, file := range files {
116121
filesFound++
117122
out <- file
118123
}
119124
directoriesScanned++
125+
if countAsFailed {
126+
directoriesFailed++
127+
}
120128
}
121129

122130
//submit statistics to main thread
131+
state.DirectoriesFailed = directoriesFailed
123132
state.DirectoriesScanned = directoriesScanned
124133
state.FilesFound = filesFound
125134
}()

0 commit comments

Comments
 (0)