未验证 提交 66b1f9b9 编写于 作者: 走神的阿圆's avatar 走神的阿圆 提交者: GitHub

fix bugs when delete bos file (#805)

上级 b7726fde
...@@ -127,10 +127,16 @@ class LocalFileSystem(object): ...@@ -127,10 +127,16 @@ class LocalFileSystem(object):
fp.write(file_content) fp.write(file_content)
def append(self, filename, file_content, binary_mode=False): def append(self, filename, file_content, binary_mode=False):
try:
self._write(filename, file_content, "ab" if binary_mode else "a") self._write(filename, file_content, "ab" if binary_mode else "a")
except FileNotFoundError:
self.makedirs(os.path.dirname(filename))
def write(self, filename, file_content, binary_mode=False): def write(self, filename, file_content, binary_mode=False):
try:
self._write(filename, file_content, "ab" if binary_mode else "a") self._write(filename, file_content, "ab" if binary_mode else "a")
except FileNotFoundError:
self.makedirs(os.path.dirname(filename))
# self._write(filename, file_content, "wb" if binary_mode else "w") # self._write(filename, file_content, "wb" if binary_mode else "w")
def walk(self, dir): def walk(self, dir):
...@@ -315,13 +321,23 @@ class BosFileSystem(object): ...@@ -315,13 +321,23 @@ class BosFileSystem(object):
content_length=len(init_data)) content_length=len(init_data))
content_length = len(file_content) content_length = len(file_content)
offset = self.get_meta(bucket_name, object_key).metadata.content_length try:
offset = self.get_meta(bucket_name,
object_key).metadata.content_length
self.bos_client.append_object(bucket_name=bucket_name, self.bos_client.append_object(bucket_name=bucket_name,
key=object_key, key=object_key,
data=file_content, data=file_content,
content_md5=content_md5(file_content), content_md5=content_md5(file_content),
content_length=content_length, content_length=content_length,
offset=offset) offset=offset)
except (exception.BceServerError, exception.BceHttpClientError) as e:
init_data = b''
self.bos_client.append_object(bucket_name=bucket_name,
key=object_key,
data=init_data,
content_md5=content_md5(init_data),
content_length=len(init_data))
self._file_contents_to_add = b'' self._file_contents_to_add = b''
self._file_contents_count = 0 self._file_contents_count = 0
self._start_append_time = time.time() self._start_append_time = time.time()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册