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:
evazion
2021-10-27 20:13:36 -05:00
parent 4095d14f2a
commit f593828bb9
6 changed files with 46 additions and 19 deletions

View File

@@ -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