Class: S3Sync::LocalDirectory
- Inherits:
-
Object
- Object
- S3Sync::LocalDirectory
- Defined in:
- lib/s3sync/sync.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source) ⇒ LocalDirectory
constructor
A new instance of LocalDirectory.
- #list_files ⇒ Object
Constructor Details
#initialize(source) ⇒ LocalDirectory
Returns a new instance of LocalDirectory.
113 114 115 |
# File 'lib/s3sync/sync.rb', line 113 def initialize source @source = source end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
111 112 113 |
# File 'lib/s3sync/sync.rb', line 111 def source @source end |
Instance Method Details
#list_files ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/s3sync/sync.rb', line 117 def list_files nodes = {} # Create the directory if it does not exist if not File.exists?(@source) FileUtils.mkdir_p(@source) return nodes end # The path declared in `@source` exists, yay! Now we need read # the whole directory and add all the readable files to the # `nodes` hash. Find.find(@source) do |file| begin st = File.stat file # Might fail raise if not st.readable? # We're not interested in things we can't read rescue $stderr.puts "WARNING: Skipping unreadable file #{file}" Find.prune end # We don't support following symlinks for now, we don't need to follow # folders and I don't think we care about any other thing, right? next unless st.file? # We only need the relative path here file_name = file.gsub(/^#{@source}\/?/, '').squeeze('/') small_comparator = lambda { Digest::MD5.hexdigest File.read(file) } node = Node.new(@source.squeeze('/'), file_name, st.size, small_comparator) nodes[node.path] = node end return nodes end |