Skip to content
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
6 changes: 6 additions & 0 deletions adapters/folder/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (ifc *ImportFolderCmd) run(cmd *cobra.Command, args []string, app *app.Appl
}

ifc.app = app
if ifc.app.Jnl() == nil {
ifc.app.SetJnl(fileevent.NewRecorder(app.Log().Logger))
}
ifc.log = ifc.app.Jnl()
log := app.Log()
ifc.tz = app.GetTZ()
ifc.InclusionFlags.SetIncludeTypeExtensions()
Expand All @@ -47,6 +51,8 @@ func (ifc *ImportFolderCmd) run(cmd *cobra.Command, args []string, app *app.Appl
return errors.New("No file found matching the pattern: " + strings.Join(args, ","))
}

ifc.fsyss = fsyss

defer func() {
if err := fshelper.CloseFSs(fsyss); err != nil {
// Handle the error - log it, since we can't return it
Expand Down
4 changes: 4 additions & 0 deletions internal/cliFlags/extensionList.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const (

// SetIncludeTypeExtensions must be called once flags are parsed
func (flags *InclusionFlags) SetIncludeTypeExtensions() {
if flags.IncludedType == IncludeAll {
return
}

mediaToExtensionsMap := filetypes.MediaToExtensions()

switch flags.IncludedType {
Expand Down
41 changes: 41 additions & 0 deletions internal/cliFlags/extensionList_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cliflags

import (
"slices"
"testing"

"github.com/simulot/immich-go/internal/filetypes"
)

func TestSetIncludeTypeExtensionsDefaultNoop(t *testing.T) {
var flags InclusionFlags

flags.SetIncludeTypeExtensions()

if len(flags.IncludedExtensions) != 0 {
t.Fatalf("expected default IncludedExtensions to remain empty, got %v", flags.IncludedExtensions)
}
}

func TestSetIncludeTypeExtensionsAddsVideoAndSidecar(t *testing.T) {
var flags InclusionFlags
flags.IncludedType = IncludeVideo

flags.SetIncludeTypeExtensions()

mediaExts := filetypes.MediaToExtensions()
expected := append(
slices.Clone(mediaExts[filetypes.TypeVideo]),
mediaExts[filetypes.TypeSidecar]...,
)

for _, ext := range expected {
if !flags.IncludedExtensions.Include(ext) {
t.Fatalf("expected extension %q to be included, got %v", ext, flags.IncludedExtensions)
}
}

if len(flags.IncludedExtensions) != len(expected) {
t.Fatalf("expected exactly %d extensions, got %d (%v)", len(expected), len(flags.IncludedExtensions), flags.IncludedExtensions)
}
}
25 changes: 25 additions & 0 deletions internal/groups/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ func (p *GrouperPipeline) PipeGrouper(ctx context.Context, in chan *assets.Asset
gOut := make(chan *assets.Group) // output channel for groups
out := make(chan *assets.Asset) // output channel for the last grouper

// Fast path: no groupers configured, just forward assets as single-item groups.
if len(p.groupers) == 0 {
go func() {
defer close(gOut)
for {
select {
case <-ctx.Done():
return
case a, ok := <-in:
if !ok {
return
}
if a != nil {
select {
case <-ctx.Done():
return
case gOut <- assets.NewGroup(assets.GroupByNone, a):
}
}
}
}
}()
return gOut
}

inChans := make([]chan *assets.Asset, len(p.groupers))
outChans := make([]chan *assets.Asset, len(p.groupers))

Expand Down