Class: Hobo::Lib::S3::Local::IoHandler

Inherits:
Object
  • Object
show all
Includes:
Hobo::Logging
Defined in:
lib/hobo/lib/s3/local/iohandler.rb

Instance Method Summary collapse

Methods included from Hobo::Logging

#logger, logger

Constructor Details

#initialize(path) ⇒ IoHandler

Returns a new instance of IoHandler.



8
9
10
# File 'lib/hobo/lib/s3/local/iohandler.rb', line 8

def initialize path
  @path = path
end

Instance Method Details

#lsObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/hobo/lib/s3/local/iohandler.rb', line 12

def ls
  logger.debug("s3sync: Listing local directory: #{@path}")
  out = {}
  dir = "#{@path.chomp('/')}/"
  files = Dir.glob("#{dir}**/*")
  files.each do |file|
    out[file.gsub(/^#{dir}/, '')] = Digest::MD5.file(file).hexdigest
  end
  return out
end

#open(file, mode) ⇒ Object



23
24
25
26
27
# File 'lib/hobo/lib/s3/local/iohandler.rb', line 23

def open file, mode
  file_path = ::File.join(@path, file)
  FileUtils.mkdir_p ::File.dirname(file_path)
  File.new ::File.open(file_path, mode)
end

#rm(file) ⇒ Object



29
30
31
# File 'lib/hobo/lib/s3/local/iohandler.rb', line 29

def rm file
  ::File.unlink ::File.join(@path, file)
end