storage manager: fix b2 storage bugs.

* B2 doesn't allow the path to start with a '/' character.
* When storing the file, we have to rewind the file pointer to make sure
  we get the whole file.
This commit is contained in:
evazion
2019-12-10 13:54:57 -06:00
parent e4f4326982
commit 4b426ec5b9

View File

@@ -9,19 +9,24 @@ class StorageManager::Cloud < StorageManager
end end
def store(io, path) def store(io, path)
io.rewind # XXX caller should be responsible for this.
data = io.read data = io.read
client.put_object(bucket, path, data) client.put_object(bucket, key(path), data)
end end
def delete(path) def delete(path)
client.delete_object(bucket, path) client.delete_object(bucket, key(path))
end end
def open(path) def open(path)
file = Tempfile.new(binmode: true) file = Tempfile.new(binmode: true)
response = client.get_object(bucket, path) response = client.get_object(bucket, key(path))
file.write(response.body) file.write(response.body)
file.rewind file.rewind
file file
end end
def key(path)
path.delete_prefix("/")
end
end end