File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ var WaitTimeout = time.Second
28
28
// ErrNotExist is a sentinel error for non existing file
29
29
var ErrNotExist = errors .New ("file does not exist" )
30
30
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
+
31
34
// Exiftool is the exiftool utility wrapper
32
35
type Exiftool struct {
33
36
lock sync.Mutex
@@ -144,14 +147,17 @@ func (e *Exiftool) ExtractMetadata(files ...string) []FileMetadata {
144
147
for i , f := range files {
145
148
fms [i ].File = f
146
149
147
- if _ , err := os .Stat (f ); err != nil {
150
+ s , err := os .Stat (f )
151
+ if err != nil {
152
+ fms [i ].Err = err
148
153
if os .IsNotExist (err ) {
149
154
fms [i ].Err = ErrNotExist
150
- continue
151
155
}
156
+ continue
157
+ }
152
158
153
- fms [ i ]. Err = err
154
-
159
+ if s . IsDir () {
160
+ fms [ i ]. Err = ErrNotFile
155
161
continue
156
162
}
157
163
Original file line number Diff line number Diff line change @@ -614,3 +614,13 @@ func copyFile(src, dest string) (err error) {
614
614
}
615
615
return nil
616
616
}
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
+ }
You can’t perform that action at this time.
0 commit comments