fsevents_to_vm 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bcb778ce441e59e1c508839c74ab72f129315328
4
+ data.tar.gz: cb6a7c1a54cf648fd54f44d2b17e2321ce0bd645
5
+ SHA512:
6
+ metadata.gz: db5a302a53c468f1d18c73bb32cf57cec1d05b12cd92a5f00148fbee14af5616fc532e2576359adf71a63ef1fed7d485a0ebe53bbb4064f7d7770c48796fd3cc
7
+ data.tar.gz: af329d180f4ce7779666d9b01a3ed5287f9b3823c14b90e53501850dd014eafc03f2f73d2dbc111ff1566557f6fa8042770814c6398a23f263cbbea55a4de22b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## 1.0.0 - 2015-08-05
5
+
6
+ ### Changed
7
+ - Fix for some non-ASCII filenames
8
+ - Expire cache based on event time seen, not mtime
9
+
10
+ ## 0.1.0 - 2015-06-04
11
+
12
+ ### Added
13
+ - Initial release.
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fsevents_to_vm.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Brian Palmer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # FSEvents To VM
2
+
3
+ Forward OS X file system events to a VM, designed for use with Dinghy.
4
+
5
+ This is an early proof-of-concept implementation. If it works well in practice, it will be integrated into Dinghy.
6
+
7
+ # Installation
8
+
9
+ This is a ruby gem, but isn't published yet. To install, clone the repo and run:
10
+
11
+ $ rake install
12
+
13
+ ## Usage
14
+
15
+ The Dinghy VM must be running. Then in a terminal run:
16
+
17
+ $ fsevents_to_vm start
18
+
19
+ You can specify a specific directory to watch. This directory must be already mounted in the VM over NFS. By default, this means anything in your home dir:
20
+
21
+ $ fsevents_to_vm start ~/projects
22
+
23
+ ## Known Limitations
24
+
25
+ * Delete events are not forwarded.
26
+ * Multiple events for the same file within the same 1/100th of a second may cause events to be missed.
27
+ * Some directories that you are unlikely to care about are ignored, for example `~/Library`.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fsevents_to_vm"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require 'fsevents_to_vm/cli'
2
+
3
+ $0 = 'fsevents_to_vm'
4
+ FseventsToVm::Cli.start(ARGV)
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fsevents_to_vm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fsevents_to_vm"
8
+ spec.version = FseventsToVm::VERSION
9
+ spec.authors = ["Brian Palmer"]
10
+ spec.email = ["brian@codekitchen.net"]
11
+
12
+ spec.summary = %q{forward OS X file system events to a VM, designed for use with Dinghy}
13
+ spec.homepage = "https://github.com/codekitchen/fsevents_to_vm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rb-fsevent", "~> 0.9.5"
22
+ spec.add_dependency "thor", "~> 0.19.1"
23
+ spec.add_dependency "net-ssh", "~> 2.9.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,31 @@
1
+ require 'thor'
2
+ require 'fsevents_to_vm'
3
+
4
+ module FseventsToVm
5
+ class Cli < Thor
6
+ option :debug, type: :boolean, default: false
7
+ desc "start PATH",
8
+ "Watch PATH and forward filesystem touch events to the Dinghy VM."
9
+ def start(listen_dir = ENV['HOME'])
10
+ debug = options[:debug]
11
+
12
+ watcher = FseventsToVm::Watch.new(listen_dir)
13
+ path_filter = FseventsToVm::PathFilter.new
14
+ recursion_filter = FseventsToVm::RecursionFilter.new
15
+ forwarder = FseventsToVm::SshEmit.new
16
+
17
+ if debug
18
+ puts "Watching #{listen_dir} and forwarding events to Dinghy VM..."
19
+ end
20
+
21
+ watcher.run do |event|
22
+ next if path_filter.ignore?(event)
23
+ next if recursion_filter.ignore?(event)
24
+ if debug
25
+ puts "touching #{event.mtime}:#{event.path}"
26
+ end
27
+ forwarder.event(event)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ module FseventsToVm
2
+ # path: String
3
+ # mtime: String
4
+ # event_time: Time
5
+ class Event < Struct.new(:path, :mtime, :event_time)
6
+ def self.format_time(time)
7
+ time.utc.strftime("%Y%m%d%H%M.%S")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module FseventsToVm
2
+ class PathFilter
3
+ def initialize
4
+ @filter = %r{#{ENV['HOME']}/(Library|\.)|/\.(git|hg|svn)/}
5
+ end
6
+
7
+ def ignore?(event)
8
+ !!@filter.match(event.path)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module FseventsToVm
2
+ class RecursionFilter
3
+ attr_reader :recent_events
4
+
5
+ def initialize
6
+ @recent_events = {}
7
+ end
8
+
9
+ def ignore?(event)
10
+ purge_old_events!
11
+ existing_event = @recent_events[event.path]
12
+ if existing_event && existing_event.mtime == event.mtime
13
+ true
14
+ else
15
+ @recent_events[event.path] = event
16
+ false
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def purge_old_events!
23
+ cutoff = Time.now - 30
24
+ @recent_events.reject! { |path, event| event.event_time < cutoff }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'net/ssh'
2
+ require 'shellwords'
3
+ require 'tempfile'
4
+
5
+ module FseventsToVm
6
+ class SshEmit
7
+ def initialize
8
+ @ssh_config = Tempfile.new('fsevents-ssh-config')
9
+ @ssh_config.write(`cd /usr/local/var/dinghy/vagrant && vagrant ssh-config --host dinghy`)
10
+ raise("Could not read Vagrant VM ssh config") unless $?.success?
11
+ @ssh_config.flush
12
+ @ssh = Net::SSH.start('dinghy', 'docker', config: @ssh_config.path)
13
+ end
14
+
15
+ def event(event)
16
+ @ssh.exec!("touch -m -c -t #{event.mtime} #{Shellwords.escape event.path}".force_encoding(Encoding::BINARY))
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module FseventsToVm
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'rb-fsevent'
2
+
3
+ module FseventsToVm
4
+ class Watch
5
+ def initialize(*listen_dirs)
6
+ @listen_dirs = listen_dirs
7
+ @fs = FSEvent.new
8
+ end
9
+
10
+ def run
11
+ @fs.watch(@listen_dirs, file_events: true) do |files|
12
+ files.each do |file|
13
+ event = build_event(file)
14
+ yield event if event
15
+ end
16
+ end
17
+ @fs.run
18
+ end
19
+
20
+ private
21
+
22
+ def build_event(filepath)
23
+ mtime = Event.format_time(File.stat(filepath).mtime)
24
+ Event.new(filepath, mtime, Time.now)
25
+ rescue Errno::ENOENT
26
+ # TODO: handling delete events is tricky due to race conditions with rapid
27
+ # delete/create.
28
+ nil
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ require "fsevents_to_vm/version"
2
+
3
+ require 'fsevents_to_vm/event'
4
+ require 'fsevents_to_vm/watch'
5
+ require 'fsevents_to_vm/path_filter'
6
+ require 'fsevents_to_vm/recursion_filter'
7
+ require 'fsevents_to_vm/ssh_emit'
8
+
9
+ module FseventsToVm
10
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fsevents_to_vm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Palmer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rb-fsevent
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.19.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.19.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ssh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.9.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description:
84
+ email:
85
+ - brian@codekitchen.net
86
+ executables:
87
+ - fsevents_to_vm
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CHANGELOG.md
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - exe/fsevents_to_vm
101
+ - fsevents_to_vm.gemspec
102
+ - lib/fsevents_to_vm.rb
103
+ - lib/fsevents_to_vm/cli.rb
104
+ - lib/fsevents_to_vm/event.rb
105
+ - lib/fsevents_to_vm/path_filter.rb
106
+ - lib/fsevents_to_vm/recursion_filter.rb
107
+ - lib/fsevents_to_vm/ssh_emit.rb
108
+ - lib/fsevents_to_vm/version.rb
109
+ - lib/fsevents_to_vm/watch.rb
110
+ homepage: https://github.com/codekitchen/fsevents_to_vm
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.7
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: forward OS X file system events to a VM, designed for use with Dinghy
134
+ test_files: []