Files
danbooru/app/logical/storage_manager/rclone.rb
evazion 56d787a17f storage manager: make rclone path configurable.
Fix bug where pruning uploads failed because the rclone binary couldn't
be found. The upload pruner runs under cron, which has a fixed default
$PATH of "/bin:/usr/bin", but in production rclone is installed under
/usr/local/bin. This caused the upload pruner to fail, which prevented
the rest of daily maintenance from running.
2019-12-28 00:21:40 -06:00

36 lines
823 B
Ruby

class StorageManager::Rclone < StorageManager
class Error < StandardError; end
attr_reader :remote, :bucket, :rclone_path, :rclone_options
def initialize(remote:, bucket:, rclone_path: "rclone", rclone_options: {}, **options)
@remote = remote
@bucket = bucket
@rclone_path = rclone_path
@rclone_options = rclone_options
super(**options)
end
def store(file, path)
rclone "copyto", file.path, key(path)
end
def delete(path)
rclone "delete", key(path)
end
def open(path)
file = Tempfile.new(binmode: true)
rclone "copyto", key(path), file.path
file
end
def rclone(*args)
success = system(rclone_path, *rclone_options, *args)
raise Error, "rclone #{args.join(" ")}: #{$?}" if !success
end
def key(path)
":#{remote}:#{bucket}#{path}"
end
end