Class: Twin::Job

Inherits:
Struct
  • Object
show all
Defined in:
lib/twin/scanner.rb

Overview

One YAML block from a sync-file, enriched with live filesystem state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#activeObject

Returns the value of attribute active

Returns:

  • (Object)

    the current value of active



9
10
11
# File 'lib/twin/scanner.rb', line 9

def active
  @active
end

#cmdObject

Returns the value of attribute cmd

Returns:

  • (Object)

    the current value of cmd



9
10
11
# File 'lib/twin/scanner.rb', line 9

def cmd
  @cmd
end

#conflictObject

Returns the value of attribute conflict

Returns:

  • (Object)

    the current value of conflict



9
10
11
# File 'lib/twin/scanner.rb', line 9

def conflict
  @conflict
end

#content_equalObject

Returns the value of attribute content_equal

Returns:

  • (Object)

    the current value of content_equal



9
10
11
# File 'lib/twin/scanner.rb', line 9

def content_equal
  @content_equal
end

#deleteObject

Returns the value of attribute delete

Returns:

  • (Object)

    the current value of delete



9
10
11
# File 'lib/twin/scanner.rb', line 9

def delete
  @delete
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



9
10
11
# File 'lib/twin/scanner.rb', line 9

def description
  @description
end

#directoryObject

Returns the value of attribute directory

Returns:

  • (Object)

    the current value of directory



9
10
11
# File 'lib/twin/scanner.rb', line 9

def directory
  @directory
end

#driftObject

Returns the value of attribute drift

Returns:

  • (Object)

    the current value of drift



9
10
11
# File 'lib/twin/scanner.rb', line 9

def drift
  @drift
end

#excludesObject

Returns the value of attribute excludes

Returns:

  • (Object)

    the current value of excludes



9
10
11
# File 'lib/twin/scanner.rb', line 9

def excludes
  @excludes
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



9
10
11
# File 'lib/twin/scanner.rb', line 9

def label
  @label
end

#ownedObject

Returns the value of attribute owned

Returns:

  • (Object)

    the current value of owned



9
10
11
# File 'lib/twin/scanner.rb', line 9

def owned
  @owned
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



9
10
11
# File 'lib/twin/scanner.rb', line 9

def path
  @path
end

#programObject

Returns the value of attribute program

Returns:

  • (Object)

    the current value of program



9
10
11
# File 'lib/twin/scanner.rb', line 9

def program
  @program
end

#renderObject

Returns the value of attribute render

Returns:

  • (Object)

    the current value of render



9
10
11
# File 'lib/twin/scanner.rb', line 9

def render
  @render
end

#render_outdatedObject

Returns the value of attribute render_outdated

Returns:

  • (Object)

    the current value of render_outdated



9
10
11
# File 'lib/twin/scanner.rb', line 9

def render_outdated
  @render_outdated
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



9
10
11
# File 'lib/twin/scanner.rb', line 9

def source
  @source
end

#source_existsObject

Returns the value of attribute source_exists

Returns:

  • (Object)

    the current value of source_exists



9
10
11
# File 'lib/twin/scanner.rb', line 9

def source_exists
  @source_exists
end

#source_mtimeObject

Returns the value of attribute source_mtime

Returns:

  • (Object)

    the current value of source_mtime



9
10
11
# File 'lib/twin/scanner.rb', line 9

def source_mtime
  @source_mtime
end

#sync_fileObject

Returns the value of attribute sync_file

Returns:

  • (Object)

    the current value of sync_file



9
10
11
# File 'lib/twin/scanner.rb', line 9

def sync_file
  @sync_file
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



9
10
11
# File 'lib/twin/scanner.rb', line 9

def target
  @target
end

#target_existsObject

Returns the value of attribute target_exists

Returns:

  • (Object)

    the current value of target_exists



9
10
11
# File 'lib/twin/scanner.rb', line 9

def target_exists
  @target_exists
end

#target_mtimeObject

Returns the value of attribute target_mtime

Returns:

  • (Object)

    the current value of target_mtime



9
10
11
# File 'lib/twin/scanner.rb', line 9

def target_mtime
  @target_mtime
end

#target_path_fieldObject

Returns the value of attribute target_path_field

Returns:

  • (Object)

    the current value of target_path_field



9
10
11
# File 'lib/twin/scanner.rb', line 9

def target_path_field
  @target_path_field
end

#target_unreachableObject

Returns the value of attribute target_unreachable

Returns:

  • (Object)

    the current value of target_unreachable



9
10
11
# File 'lib/twin/scanner.rb', line 9

def target_unreachable
  @target_unreachable
end

Instance Method Details

#all_excludesObject

Everything rsync must not touch: Exclude (not part of the sync at all) plus Own (part of the scope, but the target owns it).



22
# File 'lib/twin/scanner.rb', line 22

def all_excludes = excludes + (owned || [])

#remote?Boolean

Returns:

  • (Boolean)


18
# File 'lib/twin/scanner.rb', line 18

def remote?     = Twin::Remote.remote?(target)

#source_pathObject



16
# File 'lib/twin/scanner.rb', line 16

def source_path = File.join(source, path)

#statusObject



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
# File 'lib/twin/scanner.rb', line 24

def status
  return :disabled if active != 1
  return :unreachable if target_unreachable
  return :both_missing if !source_exists && !target_exists
  return :missing_source unless source_exists
  return :missing_target unless target_exists
  # Render jobs compare by content, not mtime — a rendered target's mtime
  # bears no relation to the template's.
  return render_outdated ? :source_newer : :in_sync if render
  # Directory jobs carry no mtime verdict at all: a directory's mtime
  # records the last entry added or removed — after a sync that is the
  # sync itself, and even an *excluded* file moves it. `twin status`
  # fills in `drift` by asking rsync; without it the honest answer is
  # "not checked", not a guess.
  if directory
    return :unverified unless drift
    return :target_newer if drift.conflicts.any?
    return :source_newer if drift.pending.any?
    return :in_sync
  end
  # Same bytes under a newer timestamp (a `cat >` copy) is not drift.
  return :in_sync if content_equal
  return :target_newer if conflict
  return :in_sync if source_mtime.nil? || target_mtime.nil?
  delta = source_mtime - target_mtime
  return :in_sync if delta.abs < 60
  delta > 0 ? :source_newer : :target_newer
end

#target_pathObject



17
# File 'lib/twin/scanner.rb', line 17

def target_path = File.join(target, target_path_field || path)