Skip to content

Commit

Permalink
Start to add in mtime calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jul 26, 2024
1 parent abfca3e commit bf03398
Show file tree
Hide file tree
Showing 28 changed files with 1,047 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/boyter/hashit
go 1.22

require (
github.com/djherbis/times v1.6.0
github.com/gosuri/uiprogress v0.0.1
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/spf13/cobra v1.8.1
Expand All @@ -11,7 +12,6 @@ require (
)

require (
github.com/djherbis/times v1.6.0 // indirect
github.com/gosuri/uilive v0.0.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func main() {
runtime.NumCPU(),
"number of threads processing files, by default the number of CPU cores",
)
flags.BoolVar(
&processor.MTime,
"mtime",
false,
"enable mtime output",
)

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
Expand Down
3 changes: 3 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var Debug = false
// Trace enables trace logging output which is extremely verbose
var Trace = false

// MTime enable mtime calculation and output
var MTime = false

// Progress uses ui bar to display the progress of files
var Progress = false

Expand Down
3 changes: 3 additions & 0 deletions processor/structs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package processor

import "time"

// Holds the result after processing the hashes for the file
type Result struct {
File string
Expand All @@ -16,4 +18,5 @@ type Result struct {
Sha3384 string
Sha3512 string
Bytes int64
MTime *time.Time
}
17 changes: 15 additions & 2 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"crypto/sha512"
"encoding/hex"
"fmt"
"github.com/djherbis/times"
"github.com/gosuri/uiprogress"
"github.com/minio/blake2b-simd"
"github.com/zeebo/blake3"
Expand All @@ -19,6 +20,7 @@ import (
"os"
"strings"
"sync"
"time"
)

const (
Expand All @@ -44,14 +46,23 @@ func fileProcessorWorker(input chan string, output chan Result) {
// Open the file and determine if we should read it from disk or memory map
// based on how large it is reported as being
file, err := os.OpenFile(res, os.O_RDONLY, 0644)

if err != nil {
printError(fmt.Sprintf("Unable to process file %s with error %s", res, err.Error()))
continue
}

fi, err := file.Stat()
var mtime time.Time
if MTime {
stat, err := times.Stat(res)
if err != nil {
printError(fmt.Sprintf("Unable to read mtime file %s with error %s", res, err.Error()))
return
}
mtime = stat.ModTime()
//fmt.Println(stat.ModTime().Format("2006-01-02 15:04:05"))
}

fi, err := file.Stat()
if err != nil {
printError(fmt.Sprintf("Unable to get file info for file %s with error %s", res, err.Error()))
continue
Expand Down Expand Up @@ -81,6 +92,7 @@ func fileProcessorWorker(input chan string, output chan Result) {
if err == nil {
r.File = res
r.Bytes = fsize
r.MTime = &mtime
output <- r
}

Expand Down Expand Up @@ -117,6 +129,7 @@ func fileProcessorWorker(input chan string, output chan Result) {
if err == nil {
r.File = res
r.Bytes = fsize
r.MTime = &mtime
output <- r
}
}
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/djherbis/times/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions vendor/github.com/djherbis/times/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 149 additions & 0 deletions vendor/github.com/djherbis/times/ctime_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/djherbis/times/js.cover.dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/djherbis/times/js.cover.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/djherbis/times/linux.cover.dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/djherbis/times/linux.cover.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bf03398

Please sign in to comment.