@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "time"
1313
14+ "code.cloudfoundry.org/bytefmt"
1415 "github.com/fsnotify/fsnotify"
1516 "github.com/radovskyb/watcher"
1617 "golift.io/cnfg"
@@ -278,7 +279,7 @@ func (u *Unpackerr) extractTrackedItem(name string, folder *Folder, now time.Tim
278279 }
279280
280281 // create a queue counter in the main history; add to u.Map and send webhook for a new folder.
281- u .updateQueueStatus (& newStatus {Name : name , Status : QUEUED }, u .folders .Folders [name ].updated , true )
282+ item := u .updateQueueStatus (& newStatus {Name : name , Status : QUEUED }, u .folders .Folders [name ].updated , true )
282283 u .updateHistory (FolderString + ": " + name )
283284
284285 var exclude []string
@@ -297,7 +298,7 @@ func (u *Unpackerr) extractTrackedItem(name string, folder *Folder, now time.Tim
297298 DeleteOrig : false ,
298299 CBChannel : u .folders .Updates ,
299300 CBFunction : nil ,
300- Progress : u .progressUpdateCallback (name ),
301+ Progress : u .progressUpdateCallback (item ),
301302 LogFile : ! folder .config .DisableLog ,
302303 DisableRecursion : folder .config .DisableRecursion ,
303304 })
@@ -332,17 +333,15 @@ func getFileList(path string) []os.FileInfo {
332333func (u * Unpackerr ) folderXtractrCallback (resp * xtractr.Response ) {
333334 folder , ok := u .folders .Folders [resp .X .Name ]
334335
335- switch {
336- case ! ok :
336+ switch item := u . Map [ resp . X . Name ]; {
337+ case ! ok , item == nil :
337338 // It doesn't exist? weird. delete it and bail out.
339+ delete (u .folders .Folders , resp .X .Name )
338340 delete (u .Map , resp .X .Name )
341+
339342 return
340343 case ! resp .Done :
341- if u .Map [resp .X .Name ] != nil && u .Map [resp .X .Name ].Progress != nil {
342- // Update the total archive count in the progress status.
343- u .Map [resp .X .Name ].Progress .Archives = resp .Archives .Count ()
344- }
345-
344+ item .XProg .Archives = resp .Archives .Count () + resp .Extras .Count ()
346345 folder .status = EXTRACTING
347346 u .Printf ("[Folder] Extraction Started: %s, retries: %d, items in queue: %d" , resp .X .Name , folder .retries , resp .Queued )
348347 case errors .Is (resp .Error , xtractr .ErrNoCompressedFiles ):
@@ -356,9 +355,9 @@ func (u *Unpackerr) folderXtractrCallback(resp *xtractr.Response) {
356355 default : // this runs in a go routine
357356 u .updateMetrics (resp , FolderString , folder .config .Path )
358357 u .Printf ("[Folder] Extraction Finished: %s => elapsed: %v, archives: %d, " +
359- "extra archives: %d, files extracted: %d, written: %dMiB " ,
358+ "extra archives: %d, files extracted: %d, written: %sB " ,
360359 resp .X .Name , resp .Elapsed .Round (time .Second ), resp .Archives .Count (),
361- resp .Extras .Count (), len (resp .NewFiles ), resp .Size / mebiByte )
360+ resp .Extras .Count (), len (resp .NewFiles ), bytefmt . ByteSize ( resp .Size ) )
362361
363362 folder .archives = resp .Archives
364363 folder .status = EXTRACTED
@@ -557,7 +556,7 @@ type newStatus struct {
557556// updateQueueStatus for an on-going tracked extraction.
558557// This is called from a channel callback to update status in a single go routine.
559558// This is used by apps and Folders in a few other places as well.
560- func (u * Unpackerr ) updateQueueStatus (data * newStatus , now time.Time , sendHook bool ) {
559+ func (u * Unpackerr ) updateQueueStatus (data * newStatus , now time.Time , sendHook bool ) * Extract {
561560 if _ , ok := u .Map [data .Name ]; ! ok {
562561 // This is a new Folder being queued for extraction.
563562 // Arr apps do not land here. They create their own queued items in u.Map.
@@ -569,11 +568,13 @@ func (u *Unpackerr) updateQueueStatus(data *newStatus, now time.Time, sendHook b
569568 IDs : map [string ]any {"title" : data .Name }, // required or webhook may break.
570569 }
571570
571+ u .Map [data .Name ].XProg = & ExtractProgress {Extract : u .Map [data .Name ]}
572+
572573 if sendHook {
573574 u .runAllHooks (u .Map [data .Name ])
574575 }
575576
576- return
577+ return u . Map [ data . Name ]
577578 }
578579
579580 if data .Resp != nil {
@@ -586,4 +587,6 @@ func (u *Unpackerr) updateQueueStatus(data *newStatus, now time.Time, sendHook b
586587 if sendHook {
587588 u .runAllHooks (u .Map [data .Name ])
588589 }
590+
591+ return u .Map [data .Name ]
589592}
0 commit comments