Skip to content

Add progress output #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ toolchain go1.24.2

require (
github.com/spf13/pflag v1.0.6
golang.org/x/term v0.31.0
golift.io/version v0.0.2
golift.io/xtractr v0.2.3-0.20250419170021-53bfe05970fe
golift.io/xtractr v0.2.3-0.20250422011648-dfd640da4ba1
)

require (
Expand All @@ -18,6 +19,7 @@ require (
github.com/sshaman1101/dcompress v0.0.0-20200109162717-50436a6332de // indirect
github.com/therootcompany/xz v1.0.1 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/sys v0.32.0 // indirect
)

require (
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -255,8 +259,8 @@ golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48 h1:c7cJWRr0cUnFHKtq072esKz
golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I=
golift.io/version v0.0.2 h1:i0gXRuSDHKs4O0sVDUg4+vNIuOxYoXhaxspftu2FRTE=
golift.io/version v0.0.2/go.mod h1:76aHNz8/Pm7CbuxIsDi97jABL5Zui3f2uZxDm4vB6hU=
golift.io/xtractr v0.2.3-0.20250419170021-53bfe05970fe h1:fCqAf/BYLNy5BdX6IeeGIGutHqOANjIfKeYANd5Cktg=
golift.io/xtractr v0.2.3-0.20250419170021-53bfe05970fe/go.mod h1:invEOYfyBnFtegY2V2n+9K5bUEHB8pGZng1BK0U2r38=
golift.io/xtractr v0.2.3-0.20250422011648-dfd640da4ba1 h1:riqVi1hRC/d1LrP53qcYeKbsTOC7a6F9kkAFaDO3xW8=
golift.io/xtractr v0.2.3-0.20250422011648-dfd640da4ba1/go.mod h1:invEOYfyBnFtegY2V2n+9K5bUEHB8pGZng1BK0U2r38=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func main() {
pwd = "."
}

log.SetOutput(os.Stdout)

// Get 1 job and other flag info from cli args.
cliJob, flags := parseFlags(pwd)
flags.printVer()
Expand Down
2 changes: 2 additions & 0 deletions pkg/xt/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"golift.io/cnfgfile"
"golift.io/xtractr"
)

// Job defines the input data for one extraction run.
Expand All @@ -22,6 +23,7 @@ type Job struct {
DebugLog bool `json:"debugLog" toml:"debug_log" xml:"debug_log" yaml:"debugLog"`
Preserve bool `json:"preservePaths" toml:"preserve_paths" xml:"preserve_paths" yaml:"preservePaths"`
Verbose bool `json:"verbose" toml:"verbose" xml:"verbose" yaml:"verbose"`
progress chan xtractr.Progress
}

// ParseJobs checks for and reads more jobs in from 0 or more job files.
Expand Down
21 changes: 19 additions & 2 deletions pkg/xt/xt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"golang.org/x/term"
"golift.io/xtractr"
)

Expand All @@ -20,10 +21,11 @@ func Extract(job *Job) {
}

job.fixModes()
job.setupProgress()

total := archives.Count()
count := 0
size := int64(0)
size := uint64(0)
fCount := 0
start := time.Now()

Expand Down Expand Up @@ -54,14 +56,29 @@ func Extract(job *Job) {
total, size, fCount, time.Since(start).Round(time.Millisecond))
}

func (j *Job) processArchive(folder, archive string) (string, int64, []string, time.Duration, error) {
func (j *Job) setupProgress() {
every := float64(5) //nolint:mnd

isTerm := term.IsTerminal(int(os.Stdout.Fd()))
if isTerm {
every = 0.1
}

if !j.DebugLog { // Only print progress if debug is off.
j.progress = make(chan xtractr.Progress)
go xtractr.ArchiveProgress(every, j.progress, term.IsTerminal(int(os.Stdout.Fd())), false)
}
}

func (j *Job) processArchive(folder, archive string) (string, uint64, []string, time.Duration, error) {
file := &xtractr.XFile{
FilePath: archive, // Path to archive being extracted.
OutputDir: j.Output, // Folder to extract archive into.
FileMode: j.FileMode.Mode(), // Write files with this mode.
DirMode: j.DirMode.Mode(), // Write folders with this mode.
Passwords: j.Passwords, // (RAR/7zip) Archive password(s).
SquashRoot: j.SquashRoot, // Remove single root folder?
Updates: j.progress,
}
file.SetLogger(j)

Expand Down