Class: Bitferry::Rclone::Task

Inherits:
Task
  • Object
show all
Defined in:
lib/bitferry.rb

Direct Known Subclasses

Copy, Equalize, Synchronize, Update

Constant Summary collapse

PROCESS =
{
  default: ['--metadata']
}

Constants inherited from Task

Task::ROUTE

Instance Attribute Summary collapse

Attributes inherited from Task

#exclude, #generation, #include, #modified, #tag

Instance Method Summary collapse

Methods inherited from Task

[], #commit, #delete, delete, intact, live, #live?, lookup, match, new, #process_options, register, registered, reset, restore, #restore_endpoint, #show_filters, stale

Methods included from Logging

log, #log, log=

Constructor Details

#initialize(source, destination, encryption: nil, process: nil, **opts) ⇒ Task

Returns a new instance of Task.



861
862
863
864
865
866
867
# File 'lib/bitferry.rb', line 861

def initialize(source, destination, encryption: nil, process: nil, **opts)
  super(**opts)
  @process_options = Bitferry.optional(process, PROCESS)
  @source = source.is_a?(Endpoint) ? source : Bitferry.endpoint(source)
  @destination = destination.is_a?(Endpoint) ? destination : Bitferry.endpoint(destination)
  @encryption = encryption
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



846
847
848
# File 'lib/bitferry.rb', line 846

def destination
  @destination
end

#encryptionObject (readonly)

Returns the value of attribute encryption.



849
850
851
# File 'lib/bitferry.rb', line 849

def encryption
  @encryption
end

#sourceObject (readonly)

Returns the value of attribute source.



846
847
848
# File 'lib/bitferry.rb', line 846

def source
  @source
end

#tokenObject (readonly)

Returns the value of attribute token.



852
853
854
# File 'lib/bitferry.rb', line 852

def token
  @token
end

Instance Method Details

#common_optionsObject



900
901
902
903
904
905
906
907
908
909
910
911
# File 'lib/bitferry.rb', line 900

def common_options
  [
    '--config', Bitferry.windows? ? 'NUL' : '/dev/null',
    case Bitferry.verbosity
      when :verbose then '--verbose'
      when :quiet then '--quiet'
      else nil
    end,
    Bitferry.verbosity == :verbose ? '--progress' : nil,
    Bitferry.simulate? ? '--dry-run' : nil,
  ].compact
end

#create(*args, process: nil, **opts) ⇒ Object



870
871
872
873
# File 'lib/bitferry.rb', line 870

def create(*args, process: nil, **opts)
  super(*args, process: process, **opts)
  encryption.configure(self) unless encryption.nil?
end

#exclude_filtersObject



917
# File 'lib/bitferry.rb', line 917

def exclude_filters = ([Volume::STORAGE, Volume::STORAGE_] + exclude).collect { |x| ['--filter', "- #{x}"]}.flatten

#execute(*args) ⇒ Object

Raises:

  • (RuntimeError)


927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'lib/bitferry.rb', line 927

def execute(*args)
  cmd = [Rclone.executable] + args
  cms = cmd.collect(&:shellescape).join(' ')
  $stdout.puts cms if Bitferry.verbosity == :verbose
  log.info(cms)
  if Bitferry.ui == :gui
    t = nil
    Open3.popen2e(*cmd) do |i, oe, thr|
      while x = oe.gets; $stdout.puts(x) end
      t = thr
    end
    status = t.value
  else
    status = Open3.pipeline(cmd).first
  end
  raise RuntimeError, "rclone exit code #{status.exitstatus}" unless status.success?
  status.success?
end

#externalizeObject



954
955
956
957
958
959
960
961
# File 'lib/bitferry.rb', line 954

def externalize
  super.merge(
    source: source.externalize,
    destination: destination.externalize,
    encryption: encryption.nil? ? nil : encryption.externalize,
    rclone: process_options.empty? ? nil : process_options
  ).compact
end

#formatObject



897
# File 'lib/bitferry.rb', line 897

def format = nil

#include_filtersObject



914
# File 'lib/bitferry.rb', line 914

def include_filters = include.collect { |x| ['--filter', "+ #{x}"]}.flatten

#intact?Boolean

Returns:

  • (Boolean)


885
# File 'lib/bitferry.rb', line 885

def intact? = live? && source.intact? && destination.intact?

#processObject



947
948
949
950
951
# File 'lib/bitferry.rb', line 947

def process
  log.info("processing task #{tag}")
  encryption.process(self) unless encryption.nil?
  execute(*process_arguments)
end

#process_argumentsObject



920
921
922
923
924
# File 'lib/bitferry.rb', line 920

def process_arguments
  include_filters + exclude_filters + common_options + process_options + (
    encryption.nil? ? [source.root.to_s, destination.root.to_s] : encryption.arguments(self)
  )
end

#refers?(volume) ⇒ Boolean

Returns:

  • (Boolean)


888
# File 'lib/bitferry.rb', line 888

def refers?(volume) = source.refers?(volume) || destination.refers?(volume)

#restore(hash) ⇒ Object



964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'lib/bitferry.rb', line 964

def restore(hash)
  task = hash.fetch(:task)
  begin
    modified = hash.fetch(:modified)
  rescue
    modified = nil
    log.warn("modified key missing - flagging task #{task} out of date")
  end
  initialize(
    restore_endpoint(hash.fetch(:source)),
    restore_endpoint(hash.fetch(:destination)),
    tag: task,
    modified: modified,
    process: hash[:rclone],
    encryption: hash[:encryption].nil? ? nil : Rclone::Encryption.restore(hash[:encryption])
  )
  super(hash)
  touch if modified.nil?
end

#show_directionObject



882
# File 'lib/bitferry.rb', line 882

def show_direction = '-->'

#show_operationObject



879
# File 'lib/bitferry.rb', line 879

def show_operation = encryption.nil? ? '' : encryption.show_operation

#show_statusObject



876
# File 'lib/bitferry.rb', line 876

def show_status = "#{show_operation} #{source.show_status} #{show_direction} #{destination.show_status} #{show_filters}"

#touchObject



891
892
893
894
# File 'lib/bitferry.rb', line 891

def touch
  @generation = [source.generation, destination.generation].max + 1
  super
end