Skip to content

Commit

Permalink
add in input file processing
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Dec 15, 2024
1 parent fb9d9ce commit adda928
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func main() {
false,
"enable mtime output",
)
flags.StringVarP(
&processor.FileInput,
"input",
"i",
"",
"input file of newline seperated file locations to process",
)

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
Expand Down
73 changes: 52 additions & 21 deletions processor/processor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package processor

import (
"bufio"
"fmt"
"github.com/gosuri/uiprogress"
"io/ioutil"
Expand All @@ -12,7 +13,7 @@ import (
)

// Global Version
var Version = "1.4.0"
var Version = "1.5.0"

// Verbose enables verbose logging output
var Verbose = false
Expand Down Expand Up @@ -66,6 +67,9 @@ var StreamSize int64 = 1_000_000
// If set will enable the internal file audit logic to kick in
var FileAudit = false

// FileInput indicates we have a file passed in which consists of a
var FileInput = ""

var NoThreads = runtime.NumCPU()

// String mapping for hash names
Expand Down Expand Up @@ -130,31 +134,58 @@ func Process() {
// Files ready to be read from disk
fileListQueue := make(chan string, FileListQueueSize)

// Spawn routine to start finding files on disk
go func() {
// Check if the paths or files added exist and inform the user if they don't
for _, f := range DirFilePaths {
fp := filepath.Clean(f)
fi, err := os.Stat(fp)
if FileInput == "" {
// Spawn routine to start finding files on disk
go func() {
// Check if the paths or files added exist and inform the user if they don't
for _, f := range DirFilePaths {
fp := filepath.Clean(f)
fi, err := os.Stat(fp)

// If there is an error which is usually does not exist then exit non zero
if err != nil {
printError(fmt.Sprintf("file or directory issue: %s %s", fp, err.Error()))
os.Exit(1)
} else {
if fi.IsDir() {
if Recursive {
isDir = true
walkDirectory(fp, fileListQueue)
}
} else {
fileListQueue <- fp
}
}

// If there is an error which is usually does not exist then exit non zero
}
close(fileListQueue)
}()
} else {
// Open the file
go func() {
file, err := os.Open(FileInput)
if err != nil {
printError(fmt.Sprintf("file or directory issue: %s %s", fp, err.Error()))
printError(fmt.Sprintf("failed to open input file: %s, %s", FileInput, err.Error()))
os.Exit(1)
} else {
if fi.IsDir() {
if Recursive {
isDir = true
walkDirectory(fp, fileListQueue)
}
} else {
fileListQueue <- fp
}
}
defer file.Close()

}
close(fileListQueue)
}()
scanner := bufio.NewScanner(file)

// Read the file line by line
for scanner.Scan() {
line := scanner.Text()
fileListQueue <- line
}
close(fileListQueue)

// Check for errors during scanning
if err := scanner.Err(); err != nil {
printError(fmt.Sprintf("error reading input file: %s, %s", FileInput, err.Error()))
os.Exit(1)
}
}()
}

if Progress {
uiprogress.Start() // start rendering of progress bars
Expand Down

0 comments on commit adda928

Please sign in to comment.