vagrant-fsnotify 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vagrant-fsnotify/command-fsnotify.rb +43 -7
- data/lib/vagrant-fsnotify/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c4a59123af0c92160d68a41342002576b09edc
|
4
|
+
data.tar.gz: 0522021542087f6d5c1a9c40e31190785c3fc32e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 641fa0f680edc1d7ffc46665944cd954f1f24ec9423f864d71e33e094c973bfacbdc7fcd77f684bbef6ce4be46ade6536520674efaf449f30a9f7850a43b2580
|
7
|
+
data.tar.gz: 95eae2a86f3dbd7d1640a678371ad900da2045c6783d807fd6e49d7c3a9fb1ae7359eada47de448b3608042c204ccbd2d9126fe9254ebbc823749b5a9d49c89e
|
@@ -5,7 +5,7 @@ module VagrantPlugins::Fsnotify
|
|
5
5
|
include Vagrant::Action::Builtin::MixinSyncedFolders
|
6
6
|
|
7
7
|
def execute
|
8
|
-
@logger = Log4r::Logger.new("vagrant::commands::
|
8
|
+
@logger = Log4r::Logger.new("vagrant::commands::fsnotify")
|
9
9
|
|
10
10
|
params = OptionParser.new do |o|
|
11
11
|
o.banner = "Usage: vagrant fsnotify [vm-name]"
|
@@ -16,6 +16,7 @@ module VagrantPlugins::Fsnotify
|
|
16
16
|
return if !argv
|
17
17
|
|
18
18
|
paths = {}
|
19
|
+
ignores = []
|
19
20
|
@changes = {}
|
20
21
|
|
21
22
|
with_target_vms do |machine|
|
@@ -54,6 +55,12 @@ module VagrantPlugins::Fsnotify
|
|
54
55
|
opts: opts
|
55
56
|
}
|
56
57
|
|
58
|
+
if opts[:exclude]
|
59
|
+
Array(opts[:exclude]).each do |pattern|
|
60
|
+
ignores << exclude_to_regexp(pattern.to_s)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
57
64
|
end
|
58
65
|
|
59
66
|
end
|
@@ -61,12 +68,19 @@ module VagrantPlugins::Fsnotify
|
|
61
68
|
end
|
62
69
|
|
63
70
|
if paths.empty?
|
64
|
-
|
71
|
+
@env.ui.info("Nothing to sync, exiting...")
|
72
|
+
return 1
|
65
73
|
end
|
66
74
|
|
75
|
+
@logger.info("Listening to paths: #{paths.keys.sort.inspect}")
|
67
76
|
@logger.info("Listening via: #{Listen::Adapter.select.inspect}")
|
77
|
+
@logger.info("Ignoring #{ignores.length} paths:")
|
78
|
+
ignores.each do |ignore|
|
79
|
+
@logger.info(" -- #{ignore.to_s}")
|
80
|
+
end
|
81
|
+
|
68
82
|
listener_callback = method(:callback).to_proc.curry[paths]
|
69
|
-
listener = Listen.to(*paths.keys, &listener_callback)
|
83
|
+
listener = Listen.to(*paths.keys, ignore: ignores, &listener_callback)
|
70
84
|
|
71
85
|
# Create the callback that lets us know when we've been interrupted
|
72
86
|
queue = Queue.new
|
@@ -95,9 +109,11 @@ module VagrantPlugins::Fsnotify
|
|
95
109
|
@logger.info(" - Removed: #{removed.inspect}")
|
96
110
|
|
97
111
|
@changes.each do |rel_path, time|
|
98
|
-
@changes.delete(rel_path) if time < Time.now.to_i -
|
112
|
+
@changes.delete(rel_path) if time < Time.now.to_i - 2
|
99
113
|
end
|
100
114
|
|
115
|
+
tosync = {}
|
116
|
+
|
101
117
|
paths.each do |hostpath, folder|
|
102
118
|
|
103
119
|
modified.each do |file|
|
@@ -106,8 +122,8 @@ module VagrantPlugins::Fsnotify
|
|
106
122
|
|
107
123
|
rel_path = file.sub(hostpath, '')
|
108
124
|
|
109
|
-
if @changes[rel_path] && @changes[rel_path]
|
110
|
-
@logger.info("#{rel_path} was changed less than
|
125
|
+
if @changes[rel_path] && @changes[rel_path] >= Time.now.to_i - 2
|
126
|
+
@logger.info("#{rel_path} was changed less than two seconds ago, skipping")
|
111
127
|
next
|
112
128
|
end
|
113
129
|
|
@@ -115,7 +131,9 @@ module VagrantPlugins::Fsnotify
|
|
115
131
|
folder[:machine].ui.info("fsnotify: Changed: #{rel_path}")
|
116
132
|
|
117
133
|
guestpath = File.join(folder[:opts][:guestpath], rel_path)
|
118
|
-
|
134
|
+
|
135
|
+
tosync[folder[:machine]] = [] if !tosync.has_key?(folder[:machine])
|
136
|
+
tosync[folder[:machine]] << guestpath
|
119
137
|
|
120
138
|
end
|
121
139
|
|
@@ -123,8 +141,26 @@ module VagrantPlugins::Fsnotify
|
|
123
141
|
|
124
142
|
end
|
125
143
|
|
144
|
+
tosync.each do |machine, files|
|
145
|
+
machine.communicate.execute("touch '#{files.join("' '")}'")
|
146
|
+
end
|
147
|
+
|
126
148
|
rescue => e
|
127
149
|
@logger.error("#{e}: #{e.message}")
|
128
150
|
end
|
151
|
+
|
152
|
+
def exclude_to_regexp(exclude)
|
153
|
+
|
154
|
+
# This is REALLY ghetto, but its a start. We can improve and
|
155
|
+
# keep unit tests passing in the future.
|
156
|
+
exclude = exclude.gsub("**", "|||GLOBAL|||")
|
157
|
+
exclude = exclude.gsub("*", "|||PATH|||")
|
158
|
+
exclude = exclude.gsub("|||PATH|||", "[^/]*")
|
159
|
+
exclude = exclude.gsub("|||GLOBAL|||", ".*")
|
160
|
+
|
161
|
+
Regexp.new(exclude)
|
162
|
+
|
163
|
+
end
|
164
|
+
|
129
165
|
end
|
130
166
|
end
|