Checkpoint implementing PATCH according to Docker

This commit is contained in:
Jake Moshenko 2015-09-02 17:31:44 -04:00
parent 35919b4cc8
commit 8269d4ac90
4 changed files with 223 additions and 59 deletions

View file

@ -1,7 +1,7 @@
import tempfile
from digest.digest_tools import content_path
from util.registry.filelike import READ_UNTIL_END
class StoragePaths(object):
shared_images = 'sharedimages'
@ -90,12 +90,12 @@ class BaseStorage(StoragePaths):
def get_checksum(self, path):
raise NotImplementedError
def stream_write_to_fp(self, in_fp, out_fp, num_bytes=-1):
def stream_write_to_fp(self, in_fp, out_fp, num_bytes=READ_UNTIL_END):
""" Copy the specified number of bytes from the input file stream to the output stream. If
num_bytes < 0 copy until the stream ends.
"""
bytes_copied = 0
while bytes_copied < num_bytes or num_bytes == -1:
while bytes_copied < num_bytes or num_bytes == READ_UNTIL_END:
size_to_read = min(num_bytes - bytes_copied, self.buffer_size)
if size_to_read < 0:
size_to_read = self.buffer_size
@ -126,7 +126,7 @@ class BaseStorageV2(BaseStorage):
""" Upload the specified amount of data from the given file pointer to the chunked destination
specified, starting at the given offset. Returns the number of bytes uploaded, and a new
version of the storage_metadata. Raises InvalidChunkException if the offset or length can
not be accepted.
not be accepted. Pass length as -1 to upload as much data from the in_fp as possible.
"""
raise NotImplementedError