summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exiftool.el10
-rw-r--r--tests/exiftool-tests.el15
2 files changed, 23 insertions, 2 deletions
diff --git a/exiftool.el b/exiftool.el
index a9495c5..3e5327b 100644
--- a/exiftool.el
+++ b/exiftool.el
@@ -1,7 +1,7 @@
;;; exiftool.el --- Elisp wrapper around ExifTool -*- lexical-binding: t -*-
;; Elisp wrapper around ExifTool
-;; Copyright (C) 2017 by Arun I
+;; Copyright (C) 2017, 2019 by Arun I
;;
;; Author: Arun I <arunisaac@systemreboot.net>
;; Version: 0.3
@@ -77,6 +77,10 @@ exiftool command line application."
"\n-execute\n")
suffix))))))
+(defun exiftool--assert-file-exists (file)
+ (unless (file-exists-p file)
+ (signal 'file-missing file)))
+
(defun exiftool-read (file &rest tags)
"Read TAGS from FILE, return an alist mapping TAGS to values.
@@ -84,6 +88,7 @@ If a tag is not found, return an empty string \"\" as the
value. If no TAGS are specified, read all tags from FILE.
\(fn FILE TAG...)"
+ (exiftool--assert-file-exists file)
(mapcar
(lambda (line)
(string-match "\\([^:]*\\): \\(.*\\)" line)
@@ -105,6 +110,8 @@ value. If no TAGS are specified, read all tags from FILE.
"Copy TAGS from SOURCE file to DESTINATION file.
If no TAGS are specified, copy all tags from SOURCE."
+ (exiftool--assert-file-exists source)
+ (exiftool--assert-file-exists destination)
(apply 'exiftool-command
"-m" "-overwrite_original"
"-tagsFromFile" source
@@ -123,6 +130,7 @@ pairs. Specifying the empty string \"\" for VALUE deletes that
TAG.
\(fn FILE (TAG . VALUE)...)"
+ (exiftool--assert-file-exists file)
(apply 'exiftool-command
"-m" "-overwrite_original"
(append
diff --git a/tests/exiftool-tests.el b/tests/exiftool-tests.el
index 8d040c4..0ef5fa2 100644
--- a/tests/exiftool-tests.el
+++ b/tests/exiftool-tests.el
@@ -1,7 +1,7 @@
;;; exiftool.el --- Elisp wrapper around exiftool ;; -*- lexical-binding: t -*-
;; Elisp wrapper around exiftool
-;; Copyright (C) 2017 by Arun I
+;; Copyright (C) 2017, 2019 by Arun I
;;
;; Author: Arun I <arunisaac@systemreboot.net>
;; Keywords: data
@@ -90,6 +90,19 @@
(equal (apply 'exiftool-read temp-1 some-tags)
(apply 'exiftool-read temp-2 some-tags))))))))
+(ert-deftest read-file-not-found-test ()
+ (should-error (exiftool-read "non-existent-file.png")
+ :type 'file-missing))
+
+(ert-deftest copy-file-not-found-test ()
+ (should-error (exiftool-copy "non-existent-file-1.png"
+ "non-existent-file-2.png")
+ :type 'file-missing))
+
+(ert-deftest write-file-not-found-test ()
+ (should-error (exiftool-write "non-existent-file.png")
+ :type 'file-missing))
+
(provide 'exiftool-tests)
;;; exiftool-tests.el ends here