Skip to content

Commit

Permalink
Error ErrNotFile returned when extracting metadata from folder (#55)
Browse files Browse the repository at this point in the history
* Error ErrNotFile returned when extracting metadata from folder (#52 fix)
* Test simplification
  • Loading branch information
barasher committed Apr 10, 2022
1 parent 0cce067 commit c725199
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions exiftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var WaitTimeout = time.Second
// ErrNotExist is a sentinel error for non existing file
var ErrNotExist = errors.New("file does not exist")

// ErrNotFile is a sentinel error that is returned when a folder is provided instead of a rerular file
var ErrNotFile = errors.New("can't extract metadata from folder")

// Exiftool is the exiftool utility wrapper
type Exiftool struct {
lock sync.Mutex
Expand Down Expand Up @@ -144,14 +147,17 @@ func (e *Exiftool) ExtractMetadata(files ...string) []FileMetadata {
for i, f := range files {
fms[i].File = f

if _, err := os.Stat(f); err != nil {
s, err := os.Stat(f)
if err != nil {
fms[i].Err = err
if os.IsNotExist(err) {
fms[i].Err = ErrNotExist
continue
}
continue
}

fms[i].Err = err

if s.IsDir() {
fms[i].Err = ErrNotFile
continue
}

Expand Down
10 changes: 10 additions & 0 deletions exiftool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,13 @@ func copyFile(src, dest string) (err error) {
}
return nil
}

func TestFailOnDirectoryInput(t *testing.T) {
e, err := NewExiftool()
require.Nil(t, err)
defer e.Close()

fms := e.ExtractMetadata("./testdata")
assert.Len(t, fms, 1)
assert.NotNil(t, fms[0].Err)
}

0 comments on commit c725199

Please sign in to comment.