MCPcopy Create free account
hub / github.com/boyter/hashit / Process

Function Process

processor/processor.go:94–189  ·  view source on GitHub ↗

Process is the main entry point of the command line it sets everything up and starts running

()

Source from the content-addressed store, hash-verified

92
93// Process is the main entry point of the command line it sets everything up and starts running
94func Process() {
95 // Display the supported hashes then bail out
96 if Hashes {
97 printHashes()
98 return
99 }
100
101 // Check if we are accepting data from stdin
102 if len(DirFilePaths) == 0 {
103 stat, _ := os.Stdin.Stat()
104 if (stat.Mode() & os.ModeCharDevice) == 0 {
105 StandardInput = true
106 }
107 }
108
109 // If nothing was supplied as an argument to run against assume run against everything in the
110 // current directory recursively
111 if len(DirFilePaths) == 0 {
112 DirFilePaths = append(DirFilePaths, ".")
113 }
114
115 // If a single argument is supplied enable recursive as if its a file no problem
116 // but if its a directory the user probably wants to hash everything in that directory
117 if len(DirFilePaths) == 1 {
118 Recursive = true
119 }
120
121 // Clean up hashes by setting all input to lowercase
122 Hash = formatHashInput()
123
124 // Results ready to be printed
125 fileSummaryQueue := make(chan Result, FileListQueueSize)
126
127 if StandardInput {
128 go processStandardInput(fileSummaryQueue)
129 } else {
130 // Files ready to be read from disk
131 fileListQueue := make(chan string, FileListQueueSize)
132
133 // Spawn routine to start finding files on disk
134 go func() {
135 // Check if the paths or files added exist and inform the user if they don't
136 for _, f := range DirFilePaths {
137 fp := filepath.Clean(f)
138 fi, err := os.Stat(fp)
139
140 // If there is an error which is usually does not exist then exit non zero
141 if err != nil {
142 printError(fmt.Sprintf("file or directory issue: %s %s", fp, err.Error()))
143 os.Exit(1)
144 } else {
145 if fi.IsDir() {
146 if Recursive {
147 isDir = true
148 walkDirectory(fp, fileListQueue)
149 }
150 } else {
151 fileListQueue <- fp

Callers 1

mainFunction · 0.92

Calls 7

printHashesFunction · 0.85
formatHashInputFunction · 0.85
processStandardInputFunction · 0.85
printErrorFunction · 0.85
walkDirectoryFunction · 0.85
fileProcessorWorkerFunction · 0.85
fileSummarizeFunction · 0.85

Tested by

no test coverage detected