def close(self):
"""On closing the file, copy it back to s3 if it was opened for
writing/appending.
:rtype: int
:return: the number of bytes written
"""
self.log("closing local cache file(" + self.tmppath + ")")
self.file.close()
bytes_written = 0
if 'w' in self.mode or 'a' in self.mode:
self.log("writing updated cache file contents to S3")
k = Key(self.mgr.bucket, self.path)
try:
bytes_written = k.set_contents_from_filename(self.tmppath)
except AttributeError as err:
self.log(str(err))
raise
if not self.mgr.caching:
# remove the local copy if caching is turned off
self.remove_cached()
return bytes_written
评论列表
文章目录