Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error ErrNotFile returned when extracting metadata from folder #55

Merged
merged 2 commits into from
Apr 10, 2022
Merged
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
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() {
barasher marked this conversation as resolved.
Show resolved Hide resolved
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")
barasher marked this conversation as resolved.
Show resolved Hide resolved
assert.Len(t, fms, 1)
assert.NotNil(t, fms[0].Err)
barasher marked this conversation as resolved.
Show resolved Hide resolved
}