Class: Orefs::Planner

Inherits:
Opee::Collector
  • Object
show all
Defined in:
lib/orefs/planner.rb

Defined Under Namespace

Classes: Step

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Planner) initialize(options = {})

A new instance of Planner



7
8
9
# File 'lib/orefs/planner.rb', line 7

def initialize(options={})
  super(options)
end

Class Method Details

+ (Object) sync_steps(pd, ld, rd, master = nil)

master can be Step::LOCAL or Step::REMOTE and forces direction



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/orefs/planner.rb', line 21

def self.sync_steps(pd, ld, rd, master=nil)
  steps = {}
  lh = {}
  rh = {}
  ph = {}
  ld.entries.each { |e| lh[e.name] = e }
  rd.entries.each { |e| rh[e.name] = e }
  pd.entries.each { |e| ph[e.name] = e } unless pd.nil?
  keys = lh.keys | rh.keys
  keys.each do |name|
    le = lh[name]
    re = rh[name]
    if re.nil?
      if Step::REMOTE == master
        steps[name] = Step.new(name, Step::LOCAL, Step::REMOVE)
      else
        steps[name] = Step.new(name, Step::LOCAL, Step::COPY) if le.is_a?(::Orefs::File)
      end
    elsif le.nil?
      if Step::LOCAL == master
        steps[name] = Step.new(name, Step::REMOTE, Step::REMOVE)
      else
        steps[name] = Step.new(name, Step::REMOTE, Step::COPY) if re.is_a?(::Orefs::File)
      end
    elsif le != re # both exist but are different
      if le.class != re.class
        ::Opee::Env.warn("Conflict syncing #{ld.top_path}/#{name}. Local and remote types do not match.")
        steps[name] = Step.new(name, Step::LOCAL, Step::ERROR)
      elsif le.is_a?(::Orefs::File) || le.is_a?(::Orefs::Link)
        op = le.is_a?(::Orefs::File) ? Step::COPY : Step::LINK
        if Step::LOCAL == master
          steps[name] = Step.new(name, Step::LOCAL, op) if le.is_a?(::Orefs::File)
        elsif Step::REMOTE == master
          steps[name] = Step.new(name, Step::REMOTE, op) if re.is_a?(::Orefs::File)
        elsif le.removed
          # TBD
        elsif re.removed
          # TBD
        elsif le.mtime > re.mtime
          pe = ph[name]
          if pe.nil? || pe.mtime == re.mtime
            # Don't know if the content or the stats changed so copy it.
            steps[name] = Step.new(name, Step::LOCAL, op) if le.is_a?(::Orefs::File)
          else
            ::Opee::Env.warn("Conflict syncing #{ld.top_path}/#{name}. Both local and remote have changed.")
            steps[name] = Step.new(name, Step::LOCAL, Step::ERROR)
          end
        elsif le.mtime < re.mtime
          # Don't know if the content or the stats changed so copy it.
          steps[name] = Step.new(name, Step::REMOTE, op) if re.is_a?(::Orefs::File)
        else # same times but different can't be good
          ::Opee::Env.warn("Conflict syncing #{ld.top_path}/#{name}. Both local and remote have changed.")
          steps[name] = Step.new(name, Step::LOCAL, Step::ERROR)
        end
      end
    end
  end
  steps.empty? ? nil : steps
end

Instance Method Details

- (Object) set_options(options)



11
12
13
14
15
16
17
18
# File 'lib/orefs/planner.rb', line 11

def set_options(options)
  super(options)
  @dir_queue = options[:dir_queue]
  @copy_queue = options[:copy_queue]
  @crypt_queue = options[:crypt_queue]
  @inputs = options[:inputs]
  @fixer = options[:fixer]
end