sass 3.1.21 → 3.2.0.alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -4
- data/REVISION +1 -1
- data/Rakefile +6 -15
- data/VERSION +1 -1
- data/VERSION_NAME +1 -1
- data/lib/sass.rb +0 -1
- data/lib/sass/cache_stores/base.rb +1 -3
- data/lib/sass/cache_stores/filesystem.rb +0 -3
- data/lib/sass/css.rb +49 -145
- data/lib/sass/engine.rb +23 -47
- data/lib/sass/environment.rb +5 -30
- data/lib/sass/exec.rb +7 -30
- data/lib/sass/importers/base.rb +1 -2
- data/lib/sass/importers/filesystem.rb +13 -18
- data/lib/sass/less.rb +1 -1
- data/lib/sass/plugin.rb +8 -4
- data/lib/sass/plugin/compiler.rb +67 -93
- data/lib/sass/plugin/configuration.rb +2 -0
- data/lib/sass/plugin/staleness_checker.rb +4 -14
- data/lib/sass/repl.rb +3 -2
- data/lib/sass/script.rb +1 -0
- data/lib/sass/script/color.rb +9 -4
- data/lib/sass/script/funcall.rb +3 -16
- data/lib/sass/script/functions.rb +55 -98
- data/lib/sass/script/interpolation.rb +0 -9
- data/lib/sass/script/lexer.rb +4 -2
- data/lib/sass/script/list.rb +0 -8
- data/lib/sass/script/literal.rb +20 -5
- data/lib/sass/script/node.rb +0 -8
- data/lib/sass/script/number.rb +11 -35
- data/lib/sass/script/operation.rb +0 -16
- data/lib/sass/script/parser.rb +5 -12
- data/lib/sass/script/string_interpolation.rb +0 -9
- data/lib/sass/script/unary_operation.rb +0 -7
- data/lib/sass/script/variable.rb +1 -5
- data/lib/sass/scss/parser.rb +54 -191
- data/lib/sass/scss/rx.rb +3 -15
- data/lib/sass/scss/static_parser.rb +3 -3
- data/lib/sass/selector.rb +3 -15
- data/lib/sass/selector/abstract_sequence.rb +2 -11
- data/lib/sass/selector/comma_sequence.rb +3 -8
- data/lib/sass/selector/sequence.rb +11 -74
- data/lib/sass/selector/simple.rb +1 -7
- data/lib/sass/selector/simple_sequence.rb +8 -28
- data/lib/sass/shared.rb +5 -3
- data/lib/sass/tree/comment_node.rb +12 -25
- data/lib/sass/tree/debug_node.rb +1 -1
- data/lib/sass/tree/directive_node.rb +0 -5
- data/lib/sass/tree/each_node.rb +1 -1
- data/lib/sass/tree/extend_node.rb +1 -1
- data/lib/sass/tree/for_node.rb +2 -2
- data/lib/sass/tree/function_node.rb +1 -1
- data/lib/sass/tree/if_node.rb +14 -1
- data/lib/sass/tree/media_node.rb +4 -4
- data/lib/sass/tree/mixin_def_node.rb +1 -1
- data/lib/sass/tree/mixin_node.rb +2 -2
- data/lib/sass/tree/node.rb +26 -10
- data/lib/sass/tree/return_node.rb +1 -1
- data/lib/sass/tree/root_node.rb +1 -1
- data/lib/sass/tree/rule_node.rb +11 -9
- data/lib/sass/tree/variable_node.rb +1 -1
- data/lib/sass/tree/visitors/base.rb +1 -1
- data/lib/sass/tree/visitors/check_nesting.rb +36 -29
- data/lib/sass/tree/visitors/convert.rb +9 -16
- data/lib/sass/tree/visitors/cssize.rb +9 -40
- data/lib/sass/tree/visitors/perform.rb +23 -79
- data/lib/sass/tree/visitors/to_css.rb +21 -23
- data/lib/sass/tree/warn_node.rb +1 -1
- data/lib/sass/tree/while_node.rb +1 -1
- data/lib/sass/util.rb +9 -147
- data/lib/sass/version.rb +0 -14
- data/test/sass/cache_test.rb +0 -15
- data/test/sass/conversion_test.rb +8 -50
- data/test/sass/css2sass_test.rb +0 -33
- data/test/sass/engine_test.rb +32 -283
- data/test/sass/extend_test.rb +0 -315
- data/test/sass/functions_test.rb +23 -60
- data/test/sass/importer_test.rb +0 -110
- data/test/sass/more_results/more_import.css +2 -2
- data/test/sass/plugin_test.rb +13 -40
- data/test/sass/results/import.css +2 -2
- data/test/sass/results/import_charset.css +0 -1
- data/test/sass/results/import_charset_1_8.css +0 -1
- data/test/sass/results/import_charset_ibm866.css +0 -1
- data/test/sass/results/scss_import.css +2 -2
- data/test/sass/results/units.css +1 -1
- data/test/sass/script_conversion_test.rb +0 -2
- data/test/sass/script_test.rb +4 -28
- data/test/sass/scss/css_test.rb +1 -79
- data/test/sass/scss/scss_test.rb +16 -96
- data/test/sass/templates/import_charset.sass +0 -2
- data/test/sass/templates/import_charset_1_8.sass +0 -2
- data/test/sass/templates/import_charset_ibm866.sass +0 -2
- data/test/sass/test_helper.rb +1 -1
- data/test/sass/util_test.rb +0 -28
- data/test/test_helper.rb +0 -2
- data/vendor/{listen → fssm}/LICENSE +1 -1
- data/vendor/fssm/README.markdown +55 -0
- data/vendor/fssm/Rakefile +59 -0
- data/vendor/fssm/VERSION.yml +5 -0
- data/vendor/fssm/example.rb +9 -0
- data/vendor/fssm/fssm.gemspec +77 -0
- data/vendor/fssm/lib/fssm.rb +33 -0
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
- data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
- data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
- data/vendor/fssm/lib/fssm/monitor.rb +26 -0
- data/vendor/fssm/lib/fssm/path.rb +91 -0
- data/vendor/fssm/lib/fssm/pathname.rb +502 -0
- data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
- data/vendor/fssm/lib/fssm/state/file.rb +24 -0
- data/vendor/fssm/lib/fssm/support.rb +63 -0
- data/vendor/fssm/lib/fssm/tree.rb +176 -0
- data/vendor/fssm/profile/prof-cache.rb +40 -0
- data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
- data/vendor/fssm/profile/prof-pathname.rb +68 -0
- data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
- data/vendor/fssm/profile/prof.html +2379 -0
- data/vendor/fssm/spec/path_spec.rb +75 -0
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +14 -0
- metadata +246 -281
- data/VERSION_DATE +0 -1
- data/lib/sass/logger.rb +0 -15
- data/lib/sass/logger/base.rb +0 -32
- data/lib/sass/logger/log_level.rb +0 -49
- data/lib/sass/tree/visitors/deep_copy.rb +0 -87
- data/lib/sass/tree/visitors/extend.rb +0 -42
- data/lib/sass/tree/visitors/set_options.rb +0 -97
- data/lib/sass/util/multibyte_string_scanner.rb +0 -134
- data/test/Gemfile +0 -4
- data/test/Gemfile.lock +0 -19
- data/test/sass/fixtures/test_staleness_check_across_importers.css +0 -1
- data/test/sass/fixtures/test_staleness_check_across_importers.scss +0 -1
- data/test/sass/logger_test.rb +0 -58
- data/test/sass/templates/_double_import_loop2.sass +0 -1
- data/test/sass/templates/bork5.sass +0 -3
- data/test/sass/templates/double_import_loop1.sass +0 -1
- data/test/sass/templates/nested_bork5.sass +0 -2
- data/test/sass/templates/single_import_loop.sass +0 -1
- data/test/sass/util/multibyte_string_scanner_test.rb +0 -147
- data/vendor/listen/CHANGELOG.md +0 -147
- data/vendor/listen/Gemfile +0 -23
- data/vendor/listen/Guardfile +0 -8
- data/vendor/listen/README.md +0 -312
- data/vendor/listen/Rakefile +0 -47
- data/vendor/listen/Vagrantfile +0 -96
- data/vendor/listen/lib/listen.rb +0 -38
- data/vendor/listen/lib/listen/adapter.rb +0 -167
- data/vendor/listen/lib/listen/adapters/darwin.rb +0 -84
- data/vendor/listen/lib/listen/adapters/linux.rb +0 -110
- data/vendor/listen/lib/listen/adapters/polling.rb +0 -66
- data/vendor/listen/lib/listen/adapters/windows.rb +0 -81
- data/vendor/listen/lib/listen/directory_record.rb +0 -318
- data/vendor/listen/lib/listen/listener.rb +0 -203
- data/vendor/listen/lib/listen/multi_listener.rb +0 -121
- data/vendor/listen/lib/listen/turnstile.rb +0 -28
- data/vendor/listen/lib/listen/version.rb +0 -3
- data/vendor/listen/listen.gemspec +0 -26
- data/vendor/listen/spec/listen/adapter_spec.rb +0 -142
- data/vendor/listen/spec/listen/adapters/darwin_spec.rb +0 -31
- data/vendor/listen/spec/listen/adapters/linux_spec.rb +0 -41
- data/vendor/listen/spec/listen/adapters/polling_spec.rb +0 -68
- data/vendor/listen/spec/listen/adapters/windows_spec.rb +0 -24
- data/vendor/listen/spec/listen/directory_record_spec.rb +0 -1138
- data/vendor/listen/spec/listen/listener_spec.rb +0 -155
- data/vendor/listen/spec/listen/multi_listener_spec.rb +0 -156
- data/vendor/listen/spec/listen/turnstile_spec.rb +0 -56
- data/vendor/listen/spec/listen_spec.rb +0 -73
- data/vendor/listen/spec/spec_helper.rb +0 -18
- data/vendor/listen/spec/support/adapter_helper.rb +0 -716
- data/vendor/listen/spec/support/directory_record_helper.rb +0 -55
- data/vendor/listen/spec/support/fixtures_helper.rb +0 -29
- data/vendor/listen/spec/support/listeners_helper.rb +0 -144
- data/vendor/listen/spec/support/platform_helper.rb +0 -11
@@ -1,66 +0,0 @@
|
|
1
|
-
module Listen
|
2
|
-
module Adapters
|
3
|
-
|
4
|
-
# The default delay between checking for changes.
|
5
|
-
DEFAULT_POLLING_LATENCY = 1.0
|
6
|
-
|
7
|
-
# Polling Adapter that works cross-platform and
|
8
|
-
# has no dependencies. This is the adapter that
|
9
|
-
# uses the most CPU processing power and has higher
|
10
|
-
# file IO that the other implementations.
|
11
|
-
#
|
12
|
-
class Polling < Adapter
|
13
|
-
|
14
|
-
# Initialize the Adapter. See {Listen::Adapter#initialize} for more info.
|
15
|
-
#
|
16
|
-
def initialize(directories, options = {}, &callback)
|
17
|
-
@latency ||= DEFAULT_POLLING_LATENCY
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
# Start the adapter.
|
22
|
-
#
|
23
|
-
# @param [Boolean] blocking whether or not to block the current thread after starting
|
24
|
-
#
|
25
|
-
def start(blocking = true)
|
26
|
-
@mutex.synchronize do
|
27
|
-
return if @stop == false
|
28
|
-
super
|
29
|
-
end
|
30
|
-
|
31
|
-
@poll_thread = Thread.new { poll }
|
32
|
-
@poll_thread.join if blocking
|
33
|
-
end
|
34
|
-
|
35
|
-
# Stop the adapter.
|
36
|
-
#
|
37
|
-
def stop
|
38
|
-
@mutex.synchronize do
|
39
|
-
return if @stop == true
|
40
|
-
super
|
41
|
-
end
|
42
|
-
|
43
|
-
@poll_thread.join
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
# Poll listener directory for file system changes.
|
49
|
-
#
|
50
|
-
def poll
|
51
|
-
until @stop
|
52
|
-
sleep(0.1) && next if @paused
|
53
|
-
|
54
|
-
start = Time.now.to_f
|
55
|
-
@callback.call(@directories.dup, :recursive => true)
|
56
|
-
@turnstile.signal
|
57
|
-
nap_time = @latency - (Time.now.to_f - start)
|
58
|
-
sleep(nap_time) if nap_time > 0
|
59
|
-
end
|
60
|
-
rescue Interrupt
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module Listen
|
4
|
-
module Adapters
|
5
|
-
|
6
|
-
# Adapter implementation for Windows `fchange`.
|
7
|
-
#
|
8
|
-
class Windows < Adapter
|
9
|
-
|
10
|
-
# Initializes the Adapter. See {Listen::Adapter#initialize} for more info.
|
11
|
-
#
|
12
|
-
def initialize(directories, options = {}, &callback)
|
13
|
-
super
|
14
|
-
@worker = init_worker
|
15
|
-
end
|
16
|
-
|
17
|
-
# Starts the adapter.
|
18
|
-
#
|
19
|
-
# @param [Boolean] blocking whether or not to block the current thread after starting
|
20
|
-
#
|
21
|
-
def start(blocking = true)
|
22
|
-
@mutex.synchronize do
|
23
|
-
return if @stop == false
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
@worker_thread = Thread.new { @worker.run }
|
28
|
-
@poll_thread = Thread.new { poll_changed_dirs(true) }
|
29
|
-
@poll_thread.join if blocking
|
30
|
-
end
|
31
|
-
|
32
|
-
# Stops the adapter.
|
33
|
-
#
|
34
|
-
def stop
|
35
|
-
@mutex.synchronize do
|
36
|
-
return if @stop == true
|
37
|
-
super
|
38
|
-
end
|
39
|
-
|
40
|
-
@worker.stop
|
41
|
-
Thread.kill(@worker_thread) if @worker_thread
|
42
|
-
@poll_thread.join
|
43
|
-
end
|
44
|
-
|
45
|
-
# Checks if the adapter is usable on the current OS.
|
46
|
-
#
|
47
|
-
# @return [Boolean] whether usable or not
|
48
|
-
#
|
49
|
-
def self.usable?
|
50
|
-
return false unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
51
|
-
|
52
|
-
require 'rb-fchange'
|
53
|
-
true
|
54
|
-
rescue LoadError
|
55
|
-
false
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
# Initializes a FChange worker and adds a watcher for
|
61
|
-
# each directory passed to the adapter.
|
62
|
-
#
|
63
|
-
# @return [FChange::Notifier] initialized worker
|
64
|
-
#
|
65
|
-
def init_worker
|
66
|
-
FChange::Notifier.new.tap do |worker|
|
67
|
-
@directories.each do |directory|
|
68
|
-
worker.watch(directory, :all_events, :recursive) do |event|
|
69
|
-
next if @paused
|
70
|
-
@mutex.synchronize do
|
71
|
-
@changed_dirs << File.expand_path(event.watcher.path)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
@@ -1,318 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'find'
|
3
|
-
require 'digest/sha1'
|
4
|
-
|
5
|
-
module Listen
|
6
|
-
|
7
|
-
# The directory record stores information about
|
8
|
-
# a directory and keeps track of changes to
|
9
|
-
# the structure of its childs.
|
10
|
-
#
|
11
|
-
class DirectoryRecord
|
12
|
-
attr_reader :directory, :paths, :sha1_checksums
|
13
|
-
|
14
|
-
DEFAULT_IGNORED_DIRECTORIES = %w[.rbx .bundle .git .svn log tmp vendor]
|
15
|
-
|
16
|
-
DEFAULT_IGNORED_EXTENSIONS = %w[.DS_Store]
|
17
|
-
|
18
|
-
# Defines the used precision based on the type of mtime returned by the
|
19
|
-
# system (whether its in milliseconds or just seconds)
|
20
|
-
#
|
21
|
-
HIGH_PRECISION_SUPPORTED = File.mtime(__FILE__).to_f.to_s[-2..-1] != '.0'
|
22
|
-
|
23
|
-
# Data structure used to save meta data about a path
|
24
|
-
#
|
25
|
-
MetaData = Struct.new(:type, :mtime)
|
26
|
-
|
27
|
-
# Class methods
|
28
|
-
#
|
29
|
-
class << self
|
30
|
-
|
31
|
-
# Creates the ignoring patterns from the default ignored
|
32
|
-
# directories and extensions. It memoizes the generated patterns
|
33
|
-
# to avoid unnecessary computation.
|
34
|
-
#
|
35
|
-
def generate_default_ignoring_patterns
|
36
|
-
@@default_ignoring_patterns ||= Array.new.tap do |default_patterns|
|
37
|
-
# Add directories
|
38
|
-
ignored_directories = DEFAULT_IGNORED_DIRECTORIES.map { |d| Regexp.escape(d) }
|
39
|
-
default_patterns << %r{^(?:#{ignored_directories.join('|')})/}
|
40
|
-
|
41
|
-
# Add extensions
|
42
|
-
ignored_extensions = DEFAULT_IGNORED_EXTENSIONS.map { |e| Regexp.escape(e) }
|
43
|
-
default_patterns << %r{(?:#{ignored_extensions.join('|')})$}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Initializes a directory record.
|
49
|
-
#
|
50
|
-
# @option [String] directory the directory to keep track of
|
51
|
-
#
|
52
|
-
def initialize(directory)
|
53
|
-
raise ArgumentError, "The path '#{directory}' is not a directory!" unless File.directory?(directory)
|
54
|
-
|
55
|
-
@directory = directory
|
56
|
-
@ignoring_patterns = Set.new
|
57
|
-
@filtering_patterns = Set.new
|
58
|
-
@sha1_checksums = Hash.new
|
59
|
-
|
60
|
-
@ignoring_patterns.merge(DirectoryRecord.generate_default_ignoring_patterns)
|
61
|
-
end
|
62
|
-
|
63
|
-
# Returns the ignoring patterns in the record
|
64
|
-
#
|
65
|
-
# @return [Array<Regexp>] the ignoring patterns
|
66
|
-
#
|
67
|
-
def ignoring_patterns
|
68
|
-
@ignoring_patterns.to_a
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns the filtering patterns used in the record to know
|
72
|
-
# which paths should be stored.
|
73
|
-
#
|
74
|
-
# @return [Array<Regexp>] the filtering patterns
|
75
|
-
#
|
76
|
-
def filtering_patterns
|
77
|
-
@filtering_patterns.to_a
|
78
|
-
end
|
79
|
-
|
80
|
-
# Adds ignoring patterns to the record.
|
81
|
-
#
|
82
|
-
# @example Ignore some paths
|
83
|
-
# ignore %r{^ignored/path/}, /man/
|
84
|
-
#
|
85
|
-
# @param [Regexp] regexp a pattern for ignoring paths
|
86
|
-
#
|
87
|
-
def ignore(*regexps)
|
88
|
-
@ignoring_patterns.merge(regexps)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Adds filtering patterns to the listener.
|
92
|
-
#
|
93
|
-
# @example Filter some files
|
94
|
-
# ignore /\.txt$/, /.*\.zip/
|
95
|
-
#
|
96
|
-
# @param [Regexp] regexp a pattern for filtering paths
|
97
|
-
#
|
98
|
-
def filter(*regexps)
|
99
|
-
@filtering_patterns.merge(regexps)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns whether a path should be ignored or not.
|
103
|
-
#
|
104
|
-
# @param [String] path the path to test.
|
105
|
-
#
|
106
|
-
# @return [Boolean]
|
107
|
-
#
|
108
|
-
def ignored?(path)
|
109
|
-
path = relative_to_base(path)
|
110
|
-
@ignoring_patterns.any? { |pattern| pattern =~ path }
|
111
|
-
end
|
112
|
-
|
113
|
-
# Returns whether a path should be filtered or not.
|
114
|
-
#
|
115
|
-
# @param [String] path the path to test.
|
116
|
-
#
|
117
|
-
# @return [Boolean]
|
118
|
-
#
|
119
|
-
def filtered?(path)
|
120
|
-
# When no filtering patterns are set, ALL files are stored.
|
121
|
-
return true if @filtering_patterns.empty?
|
122
|
-
|
123
|
-
path = relative_to_base(path)
|
124
|
-
@filtering_patterns.any? { |pattern| pattern =~ path }
|
125
|
-
end
|
126
|
-
|
127
|
-
# Finds the paths that should be stored and adds them
|
128
|
-
# to the paths' hash.
|
129
|
-
#
|
130
|
-
def build
|
131
|
-
@paths = Hash.new { |h, k| h[k] = Hash.new }
|
132
|
-
important_paths { |path| insert_path(path) }
|
133
|
-
end
|
134
|
-
|
135
|
-
# Detects changes in the passed directories, updates
|
136
|
-
# the record with the new changes and returns the changes
|
137
|
-
#
|
138
|
-
# @param [Array] directories the list of directories scan for changes
|
139
|
-
# @param [Hash] options
|
140
|
-
# @option options [Boolean] recursive scan all sub-directories recursively
|
141
|
-
# @option options [Boolean] relative_paths whether or not to use relative paths for changes
|
142
|
-
#
|
143
|
-
# @return [Hash<Array>] the changes
|
144
|
-
#
|
145
|
-
def fetch_changes(directories, options = {})
|
146
|
-
@changes = { :modified => [], :added => [], :removed => [] }
|
147
|
-
directories = directories.sort_by { |el| el.length }.reverse # diff sub-dir first
|
148
|
-
|
149
|
-
directories.each do |directory|
|
150
|
-
next unless directory[@directory] # Path is or inside directory
|
151
|
-
detect_modifications_and_removals(directory, options)
|
152
|
-
detect_additions(directory, options)
|
153
|
-
end
|
154
|
-
|
155
|
-
@changes
|
156
|
-
end
|
157
|
-
|
158
|
-
# Converts an absolute path to a path that's relative to the base directory.
|
159
|
-
#
|
160
|
-
# @param [String] path the path to convert
|
161
|
-
#
|
162
|
-
# @return [String] the relative path
|
163
|
-
#
|
164
|
-
def relative_to_base(path)
|
165
|
-
return nil unless path[@directory]
|
166
|
-
path.sub(%r{^#{Regexp.quote(@directory)}#{File::SEPARATOR}?}, '')
|
167
|
-
end
|
168
|
-
|
169
|
-
private
|
170
|
-
|
171
|
-
# Detects modifications and removals recursively in a directory.
|
172
|
-
#
|
173
|
-
# @note Modifications detection begins by checking the modification time (mtime)
|
174
|
-
# of files and then by checking content changes (using SHA1-checksum)
|
175
|
-
# when the mtime of files is not changed.
|
176
|
-
#
|
177
|
-
# @param [String] directory the path to analyze
|
178
|
-
# @param [Hash] options
|
179
|
-
# @option options [Boolean] recursive scan all sub-directories recursively
|
180
|
-
# @option options [Boolean] relative_paths whether or not to use relative paths for changes
|
181
|
-
#
|
182
|
-
def detect_modifications_and_removals(directory, options = {})
|
183
|
-
@paths[directory].each do |basename, meta_data|
|
184
|
-
path = File.join(directory, basename)
|
185
|
-
|
186
|
-
case meta_data.type
|
187
|
-
when 'Dir'
|
188
|
-
if File.directory?(path)
|
189
|
-
detect_modifications_and_removals(path, options) if options[:recursive]
|
190
|
-
else
|
191
|
-
detect_modifications_and_removals(path, { :recursive => true }.merge(options))
|
192
|
-
@paths[directory].delete(basename)
|
193
|
-
@paths.delete("#{directory}/#{basename}")
|
194
|
-
end
|
195
|
-
when 'File'
|
196
|
-
if File.exist?(path)
|
197
|
-
new_mtime = mtime_of(path)
|
198
|
-
|
199
|
-
# First check if we are in the same second (to update checksums)
|
200
|
-
# before checking the time difference
|
201
|
-
if (meta_data.mtime.to_i == new_mtime.to_i && content_modified?(path)) || meta_data.mtime < new_mtime
|
202
|
-
# Update the meta data of the files
|
203
|
-
meta_data.mtime = new_mtime
|
204
|
-
@paths[directory][basename] = meta_data
|
205
|
-
|
206
|
-
@changes[:modified] << (options[:relative_paths] ? relative_to_base(path) : path)
|
207
|
-
end
|
208
|
-
else
|
209
|
-
@paths[directory].delete(basename)
|
210
|
-
@sha1_checksums.delete(path)
|
211
|
-
@changes[:removed] << (options[:relative_paths] ? relative_to_base(path) : path)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
# Detects additions in a directory.
|
218
|
-
#
|
219
|
-
# @param [String] directory the path to analyze
|
220
|
-
# @param [Hash] options
|
221
|
-
# @option options [Boolean] recursive scan all sub-directories recursively
|
222
|
-
# @option options [Boolean] relative_paths whether or not to use relative paths for changes
|
223
|
-
#
|
224
|
-
def detect_additions(directory, options = {})
|
225
|
-
# Don't process removed directories
|
226
|
-
return unless File.exist?(directory)
|
227
|
-
|
228
|
-
Find.find(directory) do |path|
|
229
|
-
next if path == @directory
|
230
|
-
|
231
|
-
if File.directory?(path)
|
232
|
-
# Add a trailing slash to directories when checking if a directory is
|
233
|
-
# ignored to optimize finding them as Find.find doesn't.
|
234
|
-
if ignored?(path + File::SEPARATOR) || (directory != path && (!options[:recursive] && existing_path?(path)))
|
235
|
-
Find.prune # Don't look any further into this directory.
|
236
|
-
else
|
237
|
-
insert_path(path)
|
238
|
-
end
|
239
|
-
elsif !ignored?(path) && filtered?(path) && !existing_path?(path)
|
240
|
-
if File.file?(path)
|
241
|
-
@changes[:added] << (options[:relative_paths] ? relative_to_base(path) : path)
|
242
|
-
insert_path(path)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
# Returns whether or not a file's content has been modified by
|
249
|
-
# comparing the SHA1-checksum to a stored one.
|
250
|
-
#
|
251
|
-
# @param [String] path the file path
|
252
|
-
#
|
253
|
-
def content_modified?(path)
|
254
|
-
sha1_checksum = Digest::SHA1.file(path).to_s
|
255
|
-
return false if @sha1_checksums[path] == sha1_checksum
|
256
|
-
@sha1_checksums.key?(path)
|
257
|
-
rescue Errno::EACCES, Errno::ENOENT
|
258
|
-
false
|
259
|
-
ensure
|
260
|
-
@sha1_checksums[path] = sha1_checksum if sha1_checksum
|
261
|
-
end
|
262
|
-
|
263
|
-
# Traverses the base directory looking for paths that should
|
264
|
-
# be stored; thus paths that are filters or not ignored.
|
265
|
-
#
|
266
|
-
# @yield [path] an important path
|
267
|
-
#
|
268
|
-
def important_paths
|
269
|
-
Find.find(@directory) do |path|
|
270
|
-
next if path == @directory
|
271
|
-
|
272
|
-
if File.directory?(path)
|
273
|
-
# Add a trailing slash to directories when checking if a directory is
|
274
|
-
# ignored to optimize finding them as Find.find doesn't.
|
275
|
-
if ignored?(path + File::SEPARATOR)
|
276
|
-
Find.prune # Don't look any further into this directory.
|
277
|
-
else
|
278
|
-
yield(path)
|
279
|
-
end
|
280
|
-
elsif !ignored?(path) && filtered?(path)
|
281
|
-
yield(path)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
# Inserts a path with its type (Dir or File) in paths hash.
|
287
|
-
#
|
288
|
-
# @param [String] path the path to insert in @paths.
|
289
|
-
#
|
290
|
-
def insert_path(path)
|
291
|
-
meta_data = MetaData.new
|
292
|
-
meta_data.type = File.directory?(path) ? 'Dir' : 'File'
|
293
|
-
meta_data.mtime = mtime_of(path) unless meta_data.type == 'Dir' # mtimes of dirs are not used yet
|
294
|
-
@paths[File.dirname(path)][File.basename(path)] = meta_data
|
295
|
-
rescue Errno::ENOENT
|
296
|
-
end
|
297
|
-
|
298
|
-
# Returns whether or not a path exists in the paths hash.
|
299
|
-
#
|
300
|
-
# @param [String] path the path to check
|
301
|
-
#
|
302
|
-
# @return [Boolean]
|
303
|
-
#
|
304
|
-
def existing_path?(path)
|
305
|
-
@paths[File.dirname(path)][File.basename(path)] != nil
|
306
|
-
end
|
307
|
-
|
308
|
-
# Returns the modification time of a file based on the precision defined by the system
|
309
|
-
#
|
310
|
-
# @param [String] file the file for which the mtime must be returned
|
311
|
-
#
|
312
|
-
# @return [Fixnum, Float] the mtime of the file
|
313
|
-
#
|
314
|
-
def mtime_of(file)
|
315
|
-
File.lstat(file).mtime.send(HIGH_PRECISION_SUPPORTED ? :to_f : :to_i)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|