diff --git a/tosfs/core.py b/tosfs/core.py index 7b3d5b6..145c853 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -2177,21 +2177,6 @@ def fetch() -> bytes: return retryable_func_executor(fetch, max_retry_num=self.fs.max_retry_num) - def discard(self) -> None: - """Close the file without writing.""" - self._abort_mpu() - self.buffer = None # file becomes unusable - - def _abort_mpu(self) -> None: - if self.mpu: - retryable_func_executor( - lambda: self.fs.tos_client.abort_multipart_upload( - self.bucket, self.key, self.mpu.upload_id - ), - max_retry_num=self.fs.max_retry_num, - ) - self.mpu = None - def commit(self) -> None: """Complete multipart upload or PUT.""" logger.debug("Commit %s", self) @@ -2231,3 +2216,17 @@ def commit(self) -> None: self.buffer = None + def discard(self) -> None: + """Close the file without writing.""" + self._abort_mpu() + self.buffer = None # file becomes unusable + + def _abort_mpu(self) -> None: + if self.mpu: + retryable_func_executor( + lambda: self.fs.tos_client.abort_multipart_upload( + self.bucket, self.key, self.mpu.upload_id + ), + max_retry_num=self.fs.max_retry_num, + ) + self.mpu = None