Skip to content
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

Extract Bare Files #381

Merged
merged 8 commits into from
Jan 18, 2024
Merged
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: 0 additions & 4 deletions .gitattributes

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/codetests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: 'v1.54'
version: 'v1.55'

golangci-linux:
# description: "Runs golangci-lint on linux against linux and windows."
Expand All @@ -60,4 +60,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: 'v1.54'
version: 'v1.55'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
DEPLOY_KEY: ${{ secrets.AUR_DEPLOY_KEY }}

docker-ghcr-build-push:
if: github.ref != 'refs/heads/main'
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/unstable'
name: Deploy GHCR Container
runs-on: ubuntu-latest
permissions:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
golift.io/rotatorr v0.0.0-20230911015553-cd2abbd726c7
golift.io/starr v1.0.0
golift.io/version v0.0.2
golift.io/xtractr v0.2.3-0.20231212122517-824f96efe4d8
golift.io/xtractr v0.2.3-0.20240118083145-be8544c18974
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ golift.io/starr v1.0.0 h1:IDSaSL+ZYxdLT/Lg//dg/iwZ39LHO3D5CmbLCOgSXbI=
golift.io/starr v1.0.0/go.mod h1:xnUwp4vK62bDvozW9QHUYc08m6kjwaZnGw3Db65fQHw=
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.20231212122517-824f96efe4d8 h1:4BRc3tGHmCzQtD9qKAZcPpJ1kn/QOt4mrezv4QFOIiw=
golift.io/xtractr v0.2.3-0.20231212122517-824f96efe4d8/go.mod h1:1kQhdZ5fbJ1CmifS20RJ7imv0sqpqSeWWnJ06FHUG7U=
golift.io/xtractr v0.2.3-0.20240118083145-be8544c18974 h1:KJkw5mGmmDvAUFPrOAGpQuzXYB4+Tk3WSSlfbkrZM9c=
golift.io/xtractr v0.2.3-0.20240118083145-be8544c18974/go.mod h1:B608A7mLGU3gYciK+GichEUROa/Lp5NNrdmTPBb//o0=
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
24 changes: 11 additions & 13 deletions pkg/unpackerr/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type eventData struct {
cnfg *FolderConfig
name string
file string
op string
}

func (u *Unpackerr) logFolders() {
Expand Down Expand Up @@ -278,7 +279,7 @@ func (u *Unpackerr) folderXtractrCallback(resp *xtractr.Response) {
folder.step = EXTRACTING //nolint:wsl
case errors.Is(resp.Error, xtractr.ErrNoCompressedFiles):
folder.step = EXTRACTEDNOTHING
u.Printf("[Folder] Nothing Extracted: %s: %v", resp.X.Name, resp.Error)
u.Printf("[Folder] %s: %s: %v", folder.step.Desc(), resp.X.Name, resp.Error)
case resp.Error != nil:
folder.step = EXTRACTFAILED
u.Errorf("[Folder] %s: %s: %v", folder.step.Desc(), resp.X.Name, resp.Error)
Expand Down Expand Up @@ -328,18 +329,18 @@ func (f *Folders) watchFSNotify() {
return
}

f.handleFileEvent(event.Name)
f.handleFileEvent(event.Name, "f "+event.Op.String())
case event, ok := <-f.Watcher.Event:
if !ok {
return
}

f.handleFileEvent(event.Name())
f.handleFileEvent(event.Name(), "w "+event.Op.String())
}
}
}

func (f *Folders) handleFileEvent(name string) {
func (f *Folders) handleFileEvent(name, operation string) {
if strings.HasSuffix(name, suffix) {
return
}
Expand All @@ -352,29 +353,26 @@ func (f *Folders) handleFileEvent(name string) {
if !strings.HasPrefix(name, cnfg.Path) || name == cnfg.Path {
continue // Not the configured folder for the event we just got.
} else if p := filepath.Dir(name); p == cnfg.Path {
f.Events <- &eventData{name: filepath.Base(name), cnfg: cnfg, file: name}
f.Events <- &eventData{name: filepath.Base(name), cnfg: cnfg, file: name, op: operation}
} else {
f.Events <- &eventData{name: filepath.Base(p), cnfg: cnfg, file: name}
f.Events <- &eventData{name: filepath.Base(p), cnfg: cnfg, file: name, op: operation}
}
}
}

// processEvent processes the event that was received.
func (f *Folders) processEvent(event *eventData) {
dirPath := filepath.Join(event.cnfg.Path, event.name)
if stat, err := os.Stat(dirPath); err != nil {
if _, err := os.Stat(dirPath); err != nil {
// Item is unusable (probably deleted), remove it from history.
if _, ok := f.Folders[dirPath]; ok {
f.Debugf("Folder: Removing Tracked Item: %v", dirPath)
delete(f.Folders, dirPath)
f.Remove(dirPath)
}

f.Debugf("Folder: Ignored File Event '%v' (unreadable): %v", event.file, err)
f.Debugf("Folder: Ignored File Event (%s) '%s' (unreadable): %v", event.op, event.file, err)

return
} else if !stat.IsDir() {
f.Debugf("Folder: Ignoring Item '%v' (not a folder)", dirPath)
return
}

Expand All @@ -386,13 +384,13 @@ func (f *Folders) processEvent(event *eventData) {

if err := f.Add(dirPath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
f.Errorf("Folder: Tracking New Item: %v: %v", dirPath, err)
f.Errorf("Folder: Tracking New Item: %v (event: %s): %v ", dirPath, event.op, err)
}

return
}

f.Printf("[Folder] Tracking New Item: %v", dirPath)
f.Printf("[Folder] Tracking New Item: %v (event: %s)", dirPath, event.op)

f.Folders[dirPath] = &Folder{
last: time.Now(),
Expand Down
6 changes: 2 additions & 4 deletions pkg/unpackerr/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ func (u *Unpackerr) validateLidarr() error {

func (u *Unpackerr) logLidarr() {
if c := len(u.Lidarr); c == 1 {
u.Printf(" => Lidarr Config: 1 server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(" => Lidarr Config: 1 server: "+starrLogLine,
u.Lidarr[0].URL, u.Lidarr[0].APIKey != "", u.Lidarr[0].Timeout,
u.Lidarr[0].ValidSSL, u.Lidarr[0].Protocols, u.Lidarr[0].Syncthing,
u.Lidarr[0].DeleteOrig, u.Lidarr[0].DeleteDelay.Duration, u.Lidarr[0].Paths)
} else {
u.Printf(" => Lidarr Config: %d servers", c)

for _, f := range u.Lidarr {
u.Printf(" => Server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(starrLogPfx+starrLogLine,
f.URL, f.APIKey != "", f.Timeout, f.ValidSSL, f.Protocols,
f.Syncthing, f.DeleteOrig, f.DeleteDelay.Duration, f.Paths)
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/unpackerr/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import (

// satisfy gomnd.
const (
callDepth = 2 // log the line that called us.
megabyte = 1024 * 1024
logsDirMode = 0o755
callDepth = 2 // log the line that called us.
megabyte = 1024 * 1024
logsDirMode = 0o755
starrLogPfx = " => Server: "
starrLogLine = "%s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, " +
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q"
)

// ExtractStatus is our enum for an extract's status.
Expand Down Expand Up @@ -53,7 +56,7 @@ func (status ExtractStatus) Desc() string {
"Deleting",
"Delete Failed",
"Deleted",
"extractednothing",
"Nothing Extracted",
}[status]
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/unpackerr/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ func (u *Unpackerr) validateRadarr() error {

func (u *Unpackerr) logRadarr() {
if c := len(u.Radarr); c == 1 {
u.Printf(" => Radarr Config: 1 server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(" => Radarr Config: 1 server: "+starrLogLine,
u.Radarr[0].URL, u.Radarr[0].APIKey != "", u.Radarr[0].Timeout,
u.Radarr[0].ValidSSL, u.Radarr[0].Protocols, u.Radarr[0].Syncthing,
u.Radarr[0].DeleteOrig, u.Radarr[0].DeleteDelay.Duration, u.Radarr[0].Paths)
} else {
u.Printf(" => Radarr Config: %d servers", c)

for _, f := range u.Radarr {
u.Printf(" => Server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(starrLogPfx+starrLogLine,
f.URL, f.APIKey != "", f.Timeout, f.ValidSSL, f.Protocols,
f.Syncthing, f.DeleteOrig, f.DeleteDelay.Duration, f.Paths)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/unpackerr/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ func (u *Unpackerr) validateReadarr() error {

func (u *Unpackerr) logReadarr() {
if c := len(u.Readarr); c == 1 {
u.Printf(" => Readarr Config: 1 server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(" => Readarr Config: 1 server: "+starrLogLine,
u.Readarr[0].URL, u.Readarr[0].APIKey != "", u.Readarr[0].Timeout,
u.Readarr[0].ValidSSL, u.Readarr[0].Protocols, u.Readarr[0].Syncthing,
u.Readarr[0].DeleteOrig, u.Readarr[0].DeleteDelay.Duration, u.Readarr[0].Paths)
} else {
u.Printf(" => Readarr Config: %d servers", c)

for _, f := range u.Readarr {
u.Printf(" => Server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(starrLogPfx+starrLogLine,
f.URL, f.APIKey != "", f.Timeout, f.ValidSSL, f.Protocols,
f.Syncthing, f.DeleteOrig, f.DeleteDelay.Duration, f.Paths)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/unpackerr/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ func (u *Unpackerr) validateSonarr() error {

func (u *Unpackerr) logSonarr() {
if c := len(u.Sonarr); c == 1 {
u.Printf(" => Sonarr Config: 1 server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(" => Sonarr Config: 1 server: "+starrLogLine,
u.Sonarr[0].URL, u.Sonarr[0].APIKey != "", u.Sonarr[0].Timeout,
u.Sonarr[0].ValidSSL, u.Sonarr[0].Protocols, u.Sonarr[0].Syncthing,
u.Sonarr[0].DeleteOrig, u.Sonarr[0].DeleteDelay.Duration, u.Sonarr[0].Paths)
} else {
u.Printf(" => Sonarr Config: %d servers", c)

for _, f := range u.Sonarr {
u.Printf(" => Server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(starrLogPfx+starrLogLine,
f.URL, f.APIKey != "", f.Timeout, f.ValidSSL, f.Protocols,
f.Syncthing, f.DeleteOrig, f.DeleteDelay.Duration, f.Paths)
}
Expand Down
26 changes: 15 additions & 11 deletions pkg/unpackerr/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"golift.io/version"
)

// Safety constant.
const hist = "hist_"
const histNone = "hist_none"

// startTray Run()s readyTray to bring up the web server and the GUI app.
func (u *Unpackerr) startTray() {
if !ui.HasGUI() {
Expand Down Expand Up @@ -139,18 +143,18 @@ func (u *Unpackerr) watchGuiChannels() {
func (u *Unpackerr) makeHistoryChannels() {
history := systray.AddMenuItem("History", fmt.Sprintf("display last %d items queued", u.KeepHistory))
u.menu["history"] = ui.WrapMenu(history)
u.menu["hist_none"] = ui.WrapMenu(history.AddSubMenuItem("-- there is no history --", "nothing has been queued yet"))
u.menu["hist_none"].Disable()
u.menu[histNone] = ui.WrapMenu(history.AddSubMenuItem("-- there is no history --", "nothing has been queued yet"))
u.menu[histNone].Disable()

if u.KeepHistory == 0 {
u.menu["hist_none"].SetTitle("-- history disabled --")
u.menu["hist_none"].SetTooltip("history is disabled in the config")
u.menu[histNone].SetTitle("-- history disabled --")
u.menu[histNone].SetTooltip("history is disabled in the config")
}

for i := 0; i < int(u.KeepHistory); i++ {
u.menu["hist_"+strconv.Itoa(i)] = ui.WrapMenu(history.AddSubMenuItem("", ""))
u.menu["hist_"+strconv.Itoa(i)].Disable()
u.menu["hist_"+strconv.Itoa(i)].Hide()
u.menu[hist+strconv.Itoa(i)] = ui.WrapMenu(history.AddSubMenuItem("", ""))
u.menu[hist+strconv.Itoa(i)].Disable()
u.menu[hist+strconv.Itoa(i)].Hide()
}
}

Expand Down Expand Up @@ -258,7 +262,7 @@ func (u *Unpackerr) updateHistory(item string) {
}

if ui.HasGUI() && item != "" {
u.menu["hist_none"].Hide()
u.menu[histNone].Hide()
}

// u.History.Items is a slice with a set (identical) length and capacity.
Expand All @@ -274,10 +278,10 @@ func (u *Unpackerr) updateHistory(item string) {
}

if u.History.Items[i] != "" {
u.menu["hist_"+strconv.Itoa(i)].SetTitle(u.History.Items[i])
u.menu["hist_"+strconv.Itoa(i)].Show()
u.menu[hist+strconv.Itoa(i)].SetTitle(u.History.Items[i])
u.menu[hist+strconv.Itoa(i)].Show()
} else {
u.menu["hist_"+strconv.Itoa(i)].Hide()
u.menu[hist+strconv.Itoa(i)].Hide()
}
}
}
6 changes: 2 additions & 4 deletions pkg/unpackerr/whisparr.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ func (u *Unpackerr) validateWhisparr() error {

func (u *Unpackerr) logWhisparr() {
if count := len(u.Whisparr); count == 1 {
u.Printf(" => Whisparr Config: 1 server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(" => Whisparr Config: 1 server: "+starrLogLine,
u.Whisparr[0].URL, u.Whisparr[0].APIKey != "", u.Whisparr[0].Timeout,
u.Whisparr[0].ValidSSL, u.Whisparr[0].Protocols, u.Whisparr[0].Syncthing,
u.Whisparr[0].DeleteOrig, u.Whisparr[0].DeleteDelay.Duration, u.Whisparr[0].Paths)
} else if count != 0 {
u.Printf(" => Whisparr Config: %d servers", count)

for _, f := range u.Whisparr {
u.Printf(" => Server: %s, apikey:%v, timeout:%v, verify ssl:%v, protos:%s, "+
"syncthing: %v, delete_orig: %v, delete_delay: %v, paths:%q",
u.Printf(starrLogPfx+starrLogLine,
f.URL, f.APIKey != "", f.Timeout, f.ValidSSL, f.Protocols,
f.Syncthing, f.DeleteOrig, f.DeleteDelay.Duration, f.Paths)
}
Expand Down