Skip to content

Commit c725199

Browse files
authored
Error ErrNotFile returned when extracting metadata from folder (#55)
* Error ErrNotFile returned when extracting metadata from folder (#52 fix) * Test simplification
1 parent 0cce067 commit c725199

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Diff for: exiftool.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var WaitTimeout = time.Second
2828
// ErrNotExist is a sentinel error for non existing file
2929
var ErrNotExist = errors.New("file does not exist")
3030

31+
// ErrNotFile is a sentinel error that is returned when a folder is provided instead of a rerular file
32+
var ErrNotFile = errors.New("can't extract metadata from folder")
33+
3134
// Exiftool is the exiftool utility wrapper
3235
type Exiftool struct {
3336
lock sync.Mutex
@@ -144,14 +147,17 @@ func (e *Exiftool) ExtractMetadata(files ...string) []FileMetadata {
144147
for i, f := range files {
145148
fms[i].File = f
146149

147-
if _, err := os.Stat(f); err != nil {
150+
s, err := os.Stat(f)
151+
if err != nil {
152+
fms[i].Err = err
148153
if os.IsNotExist(err) {
149154
fms[i].Err = ErrNotExist
150-
continue
151155
}
156+
continue
157+
}
152158

153-
fms[i].Err = err
154-
159+
if s.IsDir() {
160+
fms[i].Err = ErrNotFile
155161
continue
156162
}
157163

Diff for: exiftool_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,13 @@ func copyFile(src, dest string) (err error) {
614614
}
615615
return nil
616616
}
617+
618+
func TestFailOnDirectoryInput(t *testing.T) {
619+
e, err := NewExiftool()
620+
require.Nil(t, err)
621+
defer e.Close()
622+
623+
fms := e.ExtractMetadata("./testdata")
624+
assert.Len(t, fms, 1)
625+
assert.NotNil(t, fms[0].Err)
626+
}

0 commit comments

Comments
 (0)