converted sha1 check in favour of checking cached file modified timestamps
This commit is contained in:
parent
8da8f6a33d
commit
f8960ec783
@ -28,6 +28,7 @@ module Guard
|
|||||||
def initialize(directory=Dir.pwd, options={})
|
def initialize(directory=Dir.pwd, options={})
|
||||||
@directory = directory.to_s
|
@directory = directory.to_s
|
||||||
@sha1_checksums_hash = {}
|
@sha1_checksums_hash = {}
|
||||||
|
@file_timestamp_hash = {}
|
||||||
@relativize_paths = options.fetch(:relativize_paths, true)
|
@relativize_paths = options.fetch(:relativize_paths, true)
|
||||||
@watch_deletions = options.deletions
|
@watch_deletions = options.deletions
|
||||||
update_last_event
|
update_last_event
|
||||||
@ -36,7 +37,7 @@ module Guard
|
|||||||
def start
|
def start
|
||||||
watch(@directory)
|
watch(@directory)
|
||||||
# populate initial sha1 hash to watch for deleted or moved files
|
# populate initial sha1 hash to watch for deleted or moved files
|
||||||
all_files.each {|path| set_sha1_checksums_hash(path, sha1_checksum(path))} if @watch_deletions
|
all_files.each {|path| set_file_timestamp_hash(path, file_timestamp(path)) } if @watch_deletions
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
@ -53,9 +54,10 @@ module Guard
|
|||||||
def modified_files(dirs, options={})
|
def modified_files(dirs, options={})
|
||||||
files = []
|
files = []
|
||||||
if @watch_deletions
|
if @watch_deletions
|
||||||
deleted_files = @sha1_checksums_hash.collect do |path, sha1|
|
deleted_files = @file_timestamp_hash.collect do |path, ts|
|
||||||
unless File.exists?(path)
|
unless File.exists?(path)
|
||||||
@sha1_checksums_hash.delete(path)
|
@sha1_checksums_hash.delete(path)
|
||||||
|
@file_timestamp_hash.delete(path)
|
||||||
"!#{path}"
|
"!#{path}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -121,7 +123,11 @@ module Guard
|
|||||||
set_sha1_checksums_hash(path, sha1_checksum(path))
|
set_sha1_checksums_hash(path, sha1_checksum(path))
|
||||||
true
|
true
|
||||||
elsif @watch_deletions
|
elsif @watch_deletions
|
||||||
file_content_modified?(path, sha1_checksum(path))
|
ts = file_timestamp(path)
|
||||||
|
if ts != @file_timestamp_hash[path]
|
||||||
|
set_file_timestamp_hash(path, ts)
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
false
|
false
|
||||||
@ -136,10 +142,18 @@ module Guard
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_file_timestamp_hash(path, file_timestamp)
|
||||||
|
@file_timestamp_hash[path] = file_timestamp
|
||||||
|
end
|
||||||
|
|
||||||
def set_sha1_checksums_hash(path, sha1_checksum)
|
def set_sha1_checksums_hash(path, sha1_checksum)
|
||||||
@sha1_checksums_hash[path] = sha1_checksum
|
@sha1_checksums_hash[path] = sha1_checksum
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_timestamp(path)
|
||||||
|
File.mtime(path).to_i
|
||||||
|
end
|
||||||
|
|
||||||
def sha1_checksum(path)
|
def sha1_checksum(path)
|
||||||
Digest::SHA1.file(path).to_s
|
Digest::SHA1.file(path).to_s
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user