@@ -32,7 +32,8 @@ type walkerCatalog map[string]directoryCatalog // by directory in the walker
3232
3333// directoryCatalog captures all files in a given directory
3434type directoryCatalog struct {
35- files map [string ]fileInfo // map of fileInfo by base name
35+ unMatchedFiles map [string ]fileInfo // map of fileInfo by base name
36+ matchedFiles map [string ]fileInfo // map of fileInfo by base name
3637}
3738
3839// fileInfo keep information collected during pass one
@@ -107,8 +108,11 @@ func (to *Takeout) passOneFsWalk(ctx context.Context, w fs.FS) error {
107108 }
108109
109110 dirCatalog := to.catalogs [w ][dir ]
110- if dirCatalog .files == nil {
111- dirCatalog .files = map [string ]fileInfo {}
111+ if dirCatalog .unMatchedFiles == nil {
112+ dirCatalog .unMatchedFiles = map [string ]fileInfo {}
113+ }
114+ if dirCatalog .matchedFiles == nil {
115+ dirCatalog .matchedFiles = map [string ]fileInfo {}
112116 }
113117 finfo , err := d .Info ()
114118 if err != nil {
@@ -151,7 +155,7 @@ func (to *Takeout) passOneFsWalk(ctx context.Context, w fs.FS) error {
151155 case immich .TypeImage :
152156 to .log .Record (ctx , fileevent .DiscoveredImage , nil , name )
153157 }
154- dirCatalog .files [base ] = fileInfo {
158+ dirCatalog .unMatchedFiles [base ] = fileInfo {
155159 length : int (finfo .Size ()),
156160 }
157161 }
@@ -240,19 +244,17 @@ func (to *Takeout) solvePuzzle(ctx context.Context) error {
240244 for d := range paths {
241245 for _ , w := range to .fsyss {
242246 l := to.catalogs [w ][d ]
243- for f := range l .files {
247+ for f := range l .unMatchedFiles {
244248 select {
245249 case <- ctx .Done ():
246250 return ctx .Err ()
247251 default :
248- if l .files [f ].md == nil {
249- if matcher (k .name , f , to .sm ) {
250- // if not already matched
251- i := l .files [f ]
252- i .md = md
253- l .files [f ] = i
254- to .log .Record (ctx , fileevent .AnalysisAssociatedMetadata , l .files [f ], f )
255- }
252+ if matcher (k .name , f , to .sm ) {
253+ i := l .unMatchedFiles [f ]
254+ i .md = md
255+ l .matchedFiles [f ] = i
256+ delete (l .unMatchedFiles , f )
257+ to .log .Record (ctx , fileevent .AnalysisAssociatedMetadata , l .unMatchedFiles [f ], f )
256258 }
257259 }
258260 }
@@ -427,7 +429,7 @@ func (to *Takeout) passTwoWalk(ctx context.Context, w fs.FS, assetChan chan *bro
427429 if ! to .sm .IsMedia (ext ) {
428430 return nil
429431 }
430- f , exist := to.catalogs [w ][dir ].files [base ]
432+ f , exist := to.catalogs [w ][dir ].matchedFiles [base ]
431433 if ! exist {
432434 return nil
433435 }
@@ -459,7 +461,7 @@ func (to *Takeout) passTwoWalk(ctx context.Context, w fs.FS, assetChan chan *bro
459461 select {
460462 case <- ctx .Done ():
461463 return ctx .Err ()
462- case assetChan <- a : // the consumer must call a.File.Release()
464+ case assetChan <- a :
463465 to .uploaded [key ] = nil // remember we have seen this file already
464466 }
465467 return nil
0 commit comments