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
15 changes: 9 additions & 6 deletions adapters/folder/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,29 @@ func (ifc *ImportFolderCmd) run(cmd *cobra.Command, args []string, app *app.Appl

ifc.app = app
ifc.processor = app.FileProcessor()
log := app.Log()
ifc.tz = app.GetTZ()
// ifc.InclusionFlags.SetIncludeTypeExtensions()
ifc.InclusionFlags.SetIncludeTypeExtensions()

// parse arguments and generate a fs.FS per argument
ifc.fsyss, err = fshelper.ParsePath(args)
fsyss, err := fshelper.ParsePath(args)
if err != nil {
return err
}
if len(ifc.fsyss) == 0 {
app.Log().Message("No file found matching the pattern: %s", strings.Join(args, ","))
if len(fsyss) == 0 {
log.Message("No file found matching the pattern: %s", strings.Join(args, ","))
return errors.New("No file found matching the pattern: " + strings.Join(args, ","))
}

defer func() {
if err := fshelper.CloseFSs(ifc.fsyss); err != nil {
if err := fshelper.CloseFSs(fsyss); err != nil {
// Handle the error - log it, since we can't return it
app.Log().Error("error closing file systems", "error", err)
log.Error("error closing file systems", "error", err)
}
}()

ifc.fsyss = fsyss

// Start the workers
ifc.pool = worker.NewPool(ifc.app.ConcurrentTask)

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)
}
}