From 168b74bd526e85ee9488276300165ce71b733c7a Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Thu, 17 Mar 2016 01:05:23 +0100 Subject: [PATCH] use first 8 characters of sha1 hex for jpegrescan version, closes #131 --- CHANGELOG.markdown | 2 ++ lib/image_optim/bin_resolver/bin.rb | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index e9c2cccb..42f8164d 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,6 +2,8 @@ ## unreleased +* Use first 8 characters of sha1 hex for jpegrescan version [#131](https://github.com/toy/image_optim/issues/131) [@toy](https://github.com/toy) + ## v0.22.1 (2016-02-21) * Fix missing old (1.x) `pngquant` version as it was output to stderr [#123](https://github.com/toy/image_optim/issues/123) [@toy](https://github.com/toy) diff --git a/lib/image_optim/bin_resolver/bin.rb b/lib/image_optim/bin_resolver/bin.rb index 6e63866f..b40fc407 100644 --- a/lib/image_optim/bin_resolver/bin.rb +++ b/lib/image_optim/bin_resolver/bin.rb @@ -3,6 +3,7 @@ require 'image_optim/bin_resolver/comparable_condition' require 'image_optim/cmd' require 'shellwords' +require 'digest/sha1' class ImageOptim class BinResolver @@ -87,8 +88,8 @@ def version_string date_str = capture("#{escaped_path} 2>&1")[date_regexp] Date.parse(date_str).strftime('%Y%m%d') if date_str when :jpegrescan - # jpegrescan has no version so just check presence - path && '-' + # jpegrescan has no version so use first 8 characters of sha1 hex + Digest::SHA1.file(path).hexdigest[0, 8] if path else fail "getting `#{name}` version is not defined" end