Skip to content

Commit

Permalink
Better handling of per-directory arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 21, 2016
1 parent da88a38 commit e899223
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/synco/compact_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def chdir_string(options)
def format_command(arguments, buffer)
arguments = arguments.dup

environment = arguments.first.is_a?(Hash) ? arguments.shift : nil
# environment = arguments.first.is_a?(Hash) ? arguments.shift : nil
options = arguments.last.is_a?(Hash) ? arguments.pop : nil

arguments = arguments.flatten.collect(&:to_s)
Expand Down
3 changes: 2 additions & 1 deletion lib/synco/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def self.build(*arguments, **options, &block)

def initialize
@events = Hash.new{|hash,key| hash[key] = Array.new}
@aborted = false
end

def freeze
Expand Down Expand Up @@ -63,7 +64,7 @@ def fire(event, *args)
handled = true

if scope
scope.instance_exec *args, &handler
scope.instance_exec(*args, &handler)
else
handler.call
end
Expand Down
8 changes: 6 additions & 2 deletions lib/synco/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ def initialize(path, **options)

@options = options
end

attr :path
attr :options


def arguments
@options[:arguments]
end

def depth
self.class.depth(@path)
end
Expand Down
14 changes: 4 additions & 10 deletions lib/synco/methods/rsync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Methods

class RSync < Method
def default_command
['rsync', '--archive', '--stats']
['rsync', '--stats']
end

# This escapes the -e argument to rsync, as it's argv parser is a bit.. unique.
Expand Down Expand Up @@ -79,12 +79,6 @@ def connect_arguments(master_server, target_server)
return ['-e', escape(command)]
end

def filter_arguments(directory)
if excludes_path = directory.options[:exclude_from]
['--exclude-from', excludes_path]
end
end

def call(scope)
master_server = scope.master_server
target_server = scope.target_server
Expand All @@ -93,7 +87,7 @@ def call(scope)
master_server.run(
*@command,
*@arguments,
*filter_arguments(directory),
*directory.arguments,
*connect_arguments(master_server, target_server),
master_server.connection_string(directory, on: master_server),
target_server.connection_string(directory, on: master_server)
Expand All @@ -113,7 +107,7 @@ def latest_name
end

def compute_incremental_path(directory)
incremental_path = File.join(snapshot_name, directory.path)
File.join(snapshot_name, directory.path)
end

def compute_link_arguments(directory, incremental_path)
Expand All @@ -138,7 +132,7 @@ def call(scope)
master_server.run(
*@command,
*@arguments,
*filter_arguments(directory),
*directory.arguments,
*connect_arguments(master_server, target_server),
*link_arguments,
master_server.connection_string(directory, on: master_server),
Expand Down
29 changes: 29 additions & 0 deletions spec/synco/directory_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env rspec

# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'synco/directory'

describe Synco::Directory.new(".", arguments: ['--foo']) do
it "should have arguments" do
expect(subject.arguments).to include('--foo')
end
end
4 changes: 1 addition & 3 deletions spec/synco/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
let(:script_scope) {Synco::ScriptScope.new(script, logger, group)}
let(:sync_scope) {Synco::TargetScope.new(script_scope, target_server)}

let(:directory) {Synco::Directory.new(".")}
let(:directory) {Synco::Directory.new(".", arguments: ['--archive'])}
let(:directory_scope) {Synco::DirectoryScope.new(sync_scope, directory)}

# This example shows all the state which goes into one single method invocation:
Expand All @@ -51,8 +51,6 @@
expect(directory_scope.target_server).to_not be == nil
expect(directory_scope.current_server).to_not be == nil

result = nil

group.wait do
Fiber.new do
subject.call(directory_scope)
Expand Down
22 changes: 2 additions & 20 deletions spec/synco/rsync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
server.root = target_path
end

script.copy(".")
script.copy '.', arguments: %W{--archive}
end

Synco::Runner.new(script).call
Expand All @@ -67,31 +67,13 @@
end
end

script.copy(".")
script.copy '.', arguments: %W{--archive}
end

Synco::Runner.new(script).call

expect(Fingerprint).to be_identical(master_path, File.join(target_path, Synco::LATEST_NAME))
end

it 'should append the excludes argument' do
script = Synco::Script.build do |script|
script.method = Synco::Methods::RSync.new

script.server(:master) do |server|
server.root = master_path
end

script.server(:backup) do |server|
server.root = target_path
end

script.copy('.', exclude_from: 'excludes')
end

expect(script.method.filter_arguments(script.directories.first)).to be == ['--exclude-from', 'excludes']
end
end

describe Synco::Methods::RSyncSnapshot do
Expand Down

0 comments on commit e899223

Please sign in to comment.