Class: S3TarBackup::Backend::FileBackend
- Inherits:
-
Object
- Object
- S3TarBackup::Backend::FileBackend
- Defined in:
- lib/s3_tar_backup/backend/file_backend.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #download_item(relative_path, local_path) ⇒ Object
-
#initialize(path) ⇒ FileBackend
constructor
A new instance of FileBackend.
- #item_exists?(relative_path) ⇒ Boolean
- #list_items(relative_path = '') ⇒ Object
- #name ⇒ Object
- #remove_item(relative_path) ⇒ Object
- #upload_item(relative_path, local_path, remove_original) ⇒ Object
Constructor Details
#initialize(path) ⇒ FileBackend
Returns a new instance of FileBackend.
11 12 13 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 11 def initialize(path) @prefix = Pathname.new(path).absolute? ? path : File.(File.join('~', path)) end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 9 def prefix @prefix end |
Instance Method Details
#download_item(relative_path, local_path) ⇒ Object
27 28 29 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 27 def download_item(relative_path, local_path) FileUtils.cp(File.join(@prefix, relative_path), local_path) end |
#item_exists?(relative_path) ⇒ Boolean
23 24 25 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 23 def item_exists?(relative_path) File.exists?(File.join(@prefix, relative_path)) end |
#list_items(relative_path = '') ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 41 def list_items(relative_path='') return [] unless File.directory?(File.join(@prefix, relative_path)) relative_path = '.' if relative_path.nil? || relative_path.empty? Dir.chdir(@prefix) do Dir.entries(relative_path).select{ |x| File.file?(x) }.map do |x| path = File.join(relative_path, x) BackendObject.new(path, File.size?(path)) end end end |
#name ⇒ Object
15 16 17 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 15 def name "File" end |
#remove_item(relative_path) ⇒ Object
19 20 21 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 19 def remove_item(relative_path) File.delete(File.join(@prefix, relative_path)) end |
#upload_item(relative_path, local_path, remove_original) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/s3_tar_backup/backend/file_backend.rb', line 31 def upload_item(relative_path, local_path, remove_original) path = File.join(@prefix, relative_path) FileUtils.mkdir_p(File.dirname(path)) unless File.directory?(File.dirname(path)) if remove_original FileUtils.mv(local_path, path) else FileUtils.cp(local_path, path) end end |