storage manager: refactor base_dir option.
Fix it so the `base_dir` option is only required by subclasses that actually use it. The StorageManager::Mirror class doesn't use it.
This commit is contained in:
@@ -2,6 +2,14 @@
|
||||
class StorageManager::Local < StorageManager
|
||||
DEFAULT_PERMISSIONS = 0o644
|
||||
|
||||
attr_reader :base_dir
|
||||
|
||||
# @param base_url [String] the base directory where files are stored (ex: "/home/danbooru/public/data")
|
||||
def initialize(base_dir: nil, **options)
|
||||
@base_dir = base_dir.to_s
|
||||
super(**options)
|
||||
end
|
||||
|
||||
def store(io, dest_path)
|
||||
temp_path = full_path(dest_path) + "-" + SecureRandom.uuid + ".tmp"
|
||||
|
||||
@@ -24,4 +32,10 @@ class StorageManager::Local < StorageManager
|
||||
def open(path)
|
||||
File.open(full_path(path), "r", binmode: true)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def full_path(path)
|
||||
File.join(base_dir, path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# A null StorageManager that doesn't store files at all. Used for testing or
|
||||
# disabling backups.
|
||||
class StorageManager::Null < StorageManager
|
||||
def initialize(base_url: "/", base_dir: "/")
|
||||
super
|
||||
def initialize
|
||||
super(base_url: nil)
|
||||
end
|
||||
|
||||
def store(io, path)
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
# @see https://rclone.org/
|
||||
class StorageManager::Rclone < StorageManager
|
||||
class Error < StandardError; end
|
||||
attr_reader :remote, :bucket, :rclone_path, :rclone_options
|
||||
attr_reader :remote, :bucket, :rclone_path, :rclone_options, :base_dir
|
||||
|
||||
def initialize(remote:, bucket:, rclone_path: "rclone", rclone_options: {}, **options)
|
||||
def initialize(remote:, bucket:, base_dir: nil, rclone_path: "rclone", rclone_options: {}, **options)
|
||||
@remote = remote
|
||||
@bucket = bucket
|
||||
@base_dir = base_dir.to_s
|
||||
@rclone_path = rclone_path
|
||||
@rclone_options = rclone_options
|
||||
super(**options)
|
||||
@@ -37,4 +38,8 @@ class StorageManager::Rclone < StorageManager
|
||||
def key(path)
|
||||
":#{remote}:#{bucket}#{full_path(path)}"
|
||||
end
|
||||
|
||||
def full_path(path)
|
||||
File.join(base_dir, path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,10 +10,11 @@ class StorageManager::SFTP < StorageManager
|
||||
non_interactive: true
|
||||
}
|
||||
|
||||
attr_reader :hosts, :ssh_options
|
||||
attr_reader :hosts, :ssh_options, :base_dir
|
||||
|
||||
def initialize(*hosts, ssh_options: {}, **options)
|
||||
def initialize(*hosts, base_dir: nil, ssh_options: {}, **options)
|
||||
@hosts = hosts
|
||||
@base_dir = base_dir.to_s
|
||||
@ssh_options = DEFAULT_SSH_OPTIONS.merge(ssh_options)
|
||||
super(**options)
|
||||
end
|
||||
@@ -73,4 +74,8 @@ class StorageManager::SFTP < StorageManager
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def full_path(path)
|
||||
File.join(base_dir, path)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user