vagrant-fsnotify 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb3aa01722396ea81758b1750ff4dbfd180bb715
4
- data.tar.gz: e8317e0b2cd4c3e768049aad6305616aec5700d4
3
+ metadata.gz: 29c4a59123af0c92160d68a41342002576b09edc
4
+ data.tar.gz: 0522021542087f6d5c1a9c40e31190785c3fc32e
5
5
  SHA512:
6
- metadata.gz: b383e054ac0f94f5ca4147ba9fdd32a6d297db96217aec24df2d0fc74881b41d8803c5d3b7331e0c984a37186d21c564ed4492563eecafe6980421437f146b45
7
- data.tar.gz: 350387bb4b28057ca4190784167f06945a82575dbdc28da02574469d1998269236da9a841213aaa19c0e7cd9ebc9fa03b796b878c0b0fd6b23922f16a3c9ad75
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::rsync-auto")
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
- return 0
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 - 1
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] > Time.now.to_i - 1
110
- @logger.info("#{rel_path} was changed less than a second ago, skipping")
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
- folder[:machine].communicate.execute("touch #{guestpath}")
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
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Fsnotify
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-fsnotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Kohlbecker