entangler 1.0.0.beta2 → 1.0.0.beta3

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: 367499550d388ad3f9642abcf1d7afc1742fd938
4
- data.tar.gz: 1e928995f5fb7ef1c5d22d8f1b20813bdfb00d84
3
+ metadata.gz: b4502e99a42282d8f8c48f7c2cd1097bece8b357
4
+ data.tar.gz: 291923c77737fa3922341d61124085f23e7ddae9
5
5
  SHA512:
6
- metadata.gz: b704a2c97c418c6fc588812bf9f854f7cb14c54d50d3da9ec5d2466fb3c113f94fa6ad6af807584f41595d6b61ed04f7ad5890a02bc683c56caf5f2596fcd639
7
- data.tar.gz: 69ca0e83d1b1ac3d0dbb0e6bf6a3f670558cad26ad5b1d761135bb5c9366880ba3ad033625f45371e4eab09587c2fc7b718c6a65ea23fb25be16b26b0123c86b
6
+ metadata.gz: 3ef8fc38e33759d2b88e65d4348a6bc60d9f0ae2e9777b7b2e812ae874205401ea2010346bf46375be6680d03eddb1b18483f462da3a4e5a56c6f26fea5e5652
7
+ data.tar.gz: 7809f15d79a760d0ad1273080ac66c018c2778319ad0d1f744bfe6ed9b5007402a46ca2f7d35e2cfa1bb7cacd578a261b56d297f220854d106013a9242d90f98
data/README.md CHANGED
@@ -18,7 +18,7 @@ $ entangler master /some/base/path user@remote:/some/remote/path
18
18
 
19
19
  ```
20
20
  $ entangler -h
21
- Entangler v1.0.0.beta2
21
+ Entangler v1.0.0.beta3
22
22
 
23
23
  Usage:
24
24
  entangler master <base_dir> <remote_user>@<remote_host>:<remote_base_dir> [options]
@@ -38,7 +38,7 @@ Options:
38
38
 
39
39
  If you specify a string, instead of a regex, it will match any path starting with that string, i.e. `-i '.git'` will ignore the `.git`
40
40
  folder and all its sub-directories. If you want to just ignore the the `.git` sub-directories but not the content in the git folder, you'll
41
- have to use regex. `-i '/^\.git(?:\/[^\/]+)+/'` will match all sub-directories of `.git/`, but not the files in `.git`.
41
+ have to use regex. `-i '/^\.git(?:\/[^\/]+)+$/'` will match all sub-directories of `.git/`, but not the files in `.git`.
42
42
 
43
43
  You can specify multiple `-i` or `--ignore` flags to ignore multiple paths.
44
44
 
data/exe/entangler CHANGED
@@ -54,7 +54,10 @@ end
54
54
  if mode == 'master'
55
55
  remote_information = ARGV.shift
56
56
 
57
- raise 'Missing destination information' unless remote_information
57
+ unless remote_information
58
+ puts 'Missing destination information'
59
+ exit 1
60
+ end
58
61
 
59
62
  user = host = path = error = nil
60
63
  remote_mode = false
@@ -89,7 +92,7 @@ if options[:ignore]
89
92
  opts[:ignore] = options[:ignore].map do |opt|
90
93
  if ToRegexp::String.literal? opt
91
94
  source, *rest = opt.as_regexp(detect: true)
92
- ::Regexp.new "^#{source}(?:/[^/]+)*", *rest
95
+ ::Regexp.new "^#{source}(?:/[^/]+)*$", *rest
93
96
  else
94
97
  opt.to_regexp(detect: true)
95
98
  end
@@ -0,0 +1,5 @@
1
+ module Entangler
2
+ class EntanglerError < StandardError; end
3
+ class ValidationError < EntanglerError; end
4
+ class VersionMismatchError < EntanglerError; end
5
+ end
@@ -40,13 +40,11 @@ module Entangler
40
40
 
41
41
  def listener
42
42
  @listener ||= begin
43
- l = Listen::Listener.new(base_dir) do |modified, added, removed|
43
+ Listen::Listener.new(base_dir, ignore!: @opts[:ignore]) do |modified, added, removed|
44
44
  process_local_changes(generate_entangled_files(added, :create) +
45
45
  generate_entangled_files(modified, :update) +
46
46
  generate_entangled_files(removed, :delete))
47
47
  end
48
- l.ignore!(@opts[:ignore])
49
- l
50
48
  end
51
49
  end
52
50
 
@@ -11,15 +11,15 @@ module Entangler
11
11
  attr_reader :base_dir
12
12
 
13
13
  def initialize(base_dir, opts = {})
14
+ validate_base_dir(base_dir)
14
15
  @base_dir = File.realpath(File.expand_path(base_dir))
15
16
  @recently_received_paths = []
16
17
  @listener_pauses = [false, false]
17
18
  @opts = opts
18
- @opts[:ignore] = [/^\.git(?:\/[^\/]+)*/] unless @opts.key?(:ignore)
19
+ @opts[:ignore] = [%r{^\.git(?:/[^/]+)*$}] unless @opts.key?(:ignore)
19
20
  @opts[:ignore] << /^\.entangler.*/
20
21
 
21
22
  validate_opts
22
- logger.info('Starting executor')
23
23
  end
24
24
 
25
25
  def generate_abs_path(rel_path)
@@ -31,19 +31,19 @@ module Entangler
31
31
  end
32
32
 
33
33
  def run
34
+ logger.info('Starting executor')
34
35
  start_listener
35
36
  start_remote_io
36
37
  Signal.trap('INT') { kill_off_threads }
37
38
  wait_for_threads
38
39
  ensure
39
40
  stop_listener
41
+ logger.info('Stopping entangler')
40
42
  end
41
43
 
42
44
  protected
43
45
 
44
- def validate_opts
45
- raise "Base directory doesn't exist" unless Dir.exist?(base_dir)
46
- end
46
+ def validate_opts; end
47
47
 
48
48
  def send_to_remote(msg = {})
49
49
  Marshal.dump(msg, @remote_writer)
@@ -61,6 +61,11 @@ module Entangler
61
61
  def log_dir
62
62
  File.join(base_dir, '.entangler', 'log')
63
63
  end
64
+
65
+ def validate_base_dir(base_dir)
66
+ raise Entangler::ValidationError, "Base directory doesn't exist" unless File.exist?(base_dir)
67
+ raise Entangler::ValidationError, 'Base directory is a file' unless File.directory?(base_dir)
68
+ end
64
69
  end
65
70
  end
66
71
  end
@@ -27,24 +27,30 @@ module Entangler
27
27
  end
28
28
 
29
29
  def validate_local_opts
30
+ unless File.exist?(@opts[:remote_base_dir])
31
+ raise Entangler::ValidationError, "Destination directory doesn't exist"
32
+ end
33
+ unless File.directory?(@opts[:remote_base_dir])
34
+ raise Entangler::ValidationError, 'Destination directory is a file'
35
+ end
30
36
  @opts[:remote_base_dir] = File.realpath(File.expand_path(@opts[:remote_base_dir]))
31
- raise "Destination directory can't be the same as the base directory" if @opts[:remote_base_dir] == base_dir
32
- raise "Destination directory doesn't exist" unless Dir.exist?(@opts[:remote_base_dir])
37
+ return unless @opts[:remote_base_dir] == base_dir
38
+ raise Entangler::ValidationError, "Destination directory can't be the same as the base directory"
33
39
  end
34
40
 
35
41
  def validate_remote_opts
36
42
  keys = @opts.keys
37
- raise 'Missing remote base dir' unless keys.include?(:remote_base_dir)
38
- raise 'Missing remote user' unless keys.include?(:remote_user)
39
- raise 'Missing remote host' unless keys.include?(:remote_host)
43
+ raise Entangler::ValidationError, 'Missing remote base dir' unless keys.include?(:remote_base_dir)
44
+ raise Entangler::ValidationError, 'Missing remote user' unless keys.include?(:remote_user)
45
+ raise Entangler::ValidationError, 'Missing remote host' unless keys.include?(:remote_host)
40
46
  validate_remote_base_dir
41
47
  validate_remote_entangler_version
42
48
  end
43
49
 
44
50
  def validate_remote_base_dir
45
51
  res = `#{generate_ssh_command("[[ -d '#{@opts[:remote_base_dir]}' ]] && echo 'ok' || echo 'missing'")}`
46
- raise 'Cannot connect to remote' if res.empty?
47
- raise 'Remote base dir invalid' unless res.strip == 'ok'
52
+ raise Entangler::ValidationError, 'Cannot connect to remote' if res.empty?
53
+ raise Entangler::ValidationError, 'Remote base dir invalid' unless res.strip == 'ok'
48
54
  end
49
55
 
50
56
  def validate_remote_entangler_version
@@ -53,8 +59,9 @@ module Entangler
53
59
  remote_version = Gem::Version.new(res.strip)
54
60
  local_version = Gem::Version.new(Entangler::VERSION)
55
61
  return unless major_version_mismatch?(local_version, remote_version)
56
- raise 'Entangler version too far apart, please update either local or remote Entangler.' \
62
+ msg = 'Entangler version too far apart, please update either local or remote Entangler.' \
57
63
  " Local version is #{local_version} and remote version is #{remote_version}."
64
+ raise Entangler::VersionMismatchError, msg
58
65
  end
59
66
 
60
67
  def major_version_mismatch?(version1, version2)
@@ -1,3 +1,3 @@
1
1
  module Entangler
2
- VERSION = '1.0.0.beta2'.freeze
2
+ VERSION = '1.0.0.beta3'.freeze
3
3
  end
data/lib/entangler.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'entangler/version'
2
+ require_relative 'entangler/errors'
2
3
  require_relative 'entangler/entangled_file'
3
4
 
4
5
  module Entangler
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entangler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta2
4
+ version: 1.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Allie
@@ -117,6 +117,7 @@ files:
117
117
  - exe/entangler
118
118
  - lib/entangler.rb
119
119
  - lib/entangler/entangled_file.rb
120
+ - lib/entangler/errors.rb
120
121
  - lib/entangler/executor/background/base.rb
121
122
  - lib/entangler/executor/background/master.rb
122
123
  - lib/entangler/executor/base.rb