aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go61
1 files changed, 6 insertions, 55 deletions
diff --git a/main.go b/main.go
index 4cad26f..886e4c7 100644
--- a/main.go
+++ b/main.go
@@ -482,45 +482,20 @@ func (dm *directoryManager) IDForDirectoryPath(
}
func isImage(path string) (bool, error) {
- cmd := exec.Command("xdg-mime", "query", "filetype", path)
-
- // XXX: Early returns may leak resources.
- stdout, err := cmd.StdoutPipe()
- if err != nil {
- return false, err
- }
- if err := cmd.Start(); err != nil {
- return false, err
- }
- out, err := io.ReadAll(stdout)
+ out, err := exec.Command("xdg-mime", "query", "filetype", path).Output()
if err != nil {
return false, err
}
- if err := cmd.Wait(); err != nil {
- return false, err
- }
+
return bytes.HasPrefix(out, []byte("image/")), nil
}
func pingImage(path string) (int, int, error) {
- cmd := exec.Command("identify", "-limit", "thread", "1", "-ping",
- "-format", "%w %h", path+"[0]")
-
- // XXX: Early returns may leak resources.
- stdout, err := cmd.StdoutPipe()
- if err != nil {
- return 0, 0, err
- }
- if err := cmd.Start(); err != nil {
- return 0, 0, err
- }
- out, err := io.ReadAll(stdout)
+ out, err := exec.Command("identify", "-limit", "thread", "1", "-ping",
+ "-format", "%w %h", path+"[0]").Output()
if err != nil {
return 0, 0, err
}
- if err := cmd.Wait(); err != nil {
- return 0, 0, err
- }
var w, h int
_, err = fmt.Fscanf(bytes.NewReader(out), "%d %d", &w, &h)
@@ -813,21 +788,10 @@ func makeThumbnail(pathImage, pathThumb string) (int, int, error) {
"-resize", "256x128>", "-colorspace", "sRGB",
"-format", "%w %h", "+write", pathThumb, "-delete", "1--1", "info:")
- // XXX: Early returns may leak resources.
- stdout, err := cmd.StdoutPipe()
- if err != nil {
- return 0, 0, err
- }
- if err := cmd.Start(); err != nil {
- return 0, 0, err
- }
- out, err := io.ReadAll(stdout)
+ out, err := cmd.Output()
if err != nil {
return 0, 0, err
}
- if err := cmd.Wait(); err != nil {
- return 0, 0, err
- }
var w, h int
_, err = fmt.Fscanf(bytes.NewReader(out), "%d %d", &w, &h)
@@ -898,23 +862,10 @@ func cmdThumbnail(args []string) error {
// --- Perceptual hash ---------------------------------------------------------
func makeDhash(hasher, pathThumb string) (uint64, error) {
- cmd := exec.Command(hasher, pathThumb)
-
- // XXX: Early returns may leak resources.
- stdout, err := cmd.StdoutPipe()
- if err != nil {
- return 0, err
- }
- if err := cmd.Start(); err != nil {
- return 0, err
- }
- out, err := io.ReadAll(stdout)
+ out, err := exec.Command(hasher, pathThumb).Output()
if err != nil {
return 0, err
}
- if err := cmd.Wait(); err != nil {
- return 0, err
- }
var hash uint64
_, err = fmt.Fscanf(bytes.NewReader(out), "%x", &hash)