This is an automated email from the ASF dual-hosted git repository.

suyanhanx pushed a commit to branch empty-file-test
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/empty-file-test by this push:
     new 4fa663122 move path check to path build block
     new 0558a6a93 Merge branch 'empty-file-test' of 
github.com:apache/incubator-opendal into empty-file-test
4fa663122 is described below

commit 4fa66312290faef789b4be651f6e59fb7313f507
Author: suyanhanx <[email protected]>
AuthorDate: Mon Sep 18 12:47:54 2023 +0800

    move path check to path build block
    
    Signed-off-by: suyanhanx <[email protected]>
---
 core/src/services/fs/backend.rs | 42 +++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/core/src/services/fs/backend.rs b/core/src/services/fs/backend.rs
index c28342eba..e1293f8b9 100644
--- a/core/src/services/fs/backend.rs
+++ b/core/src/services/fs/backend.rs
@@ -368,11 +368,20 @@ impl Accessor for FsBackend {
     }
 
     async fn write(&self, path: &str, op: OpWrite) -> Result<(RpWrite, 
Self::Writer)> {
-        let (target_path, mut tmp_path) = if let Some(atomic_write_dir) = 
&self.atomic_write_dir {
+        let (target_path, tmp_path) = if let Some(atomic_write_dir) = 
&self.atomic_write_dir {
             let target_path = Self::ensure_write_abs_path(&self.root, 
path).await?;
             let tmp_path =
                 Self::ensure_write_abs_path(atomic_write_dir, 
&tmp_file_of(path)).await?;
-            (target_path, Some(tmp_path))
+
+            // If the target file exists, we should append to the end of it 
directly.
+            if tokio::fs::try_exists(&target_path)
+                .await
+                .map_err(parse_io_error)?
+            {
+                (target_path, None)
+            } else {
+                (target_path, Some(tmp_path))
+            }
         } else {
             let p = Self::ensure_write_abs_path(&self.root, path).await?;
 
@@ -383,14 +392,6 @@ impl Accessor for FsBackend {
         open_options.create(true).write(true);
         if op.append() {
             open_options.append(true);
-
-            // If the target file exists, we should append to the end of it 
directly.
-            if tokio::fs::try_exists(&target_path)
-                .await
-                .map_err(parse_io_error)?
-            {
-                tmp_path = None;
-            }
         } else {
             open_options.truncate(true);
         }
@@ -567,11 +568,20 @@ impl Accessor for FsBackend {
     }
 
     fn blocking_write(&self, path: &str, op: OpWrite) -> Result<(RpWrite, 
Self::BlockingWriter)> {
-        let (target_path, mut tmp_path) = if let Some(atomic_write_dir) = 
&self.atomic_write_dir {
+        let (target_path, tmp_path) = if let Some(atomic_write_dir) = 
&self.atomic_write_dir {
             let target_path = Self::blocking_ensure_write_abs_path(&self.root, 
path)?;
             let tmp_path =
                 Self::blocking_ensure_write_abs_path(atomic_write_dir, 
&tmp_file_of(path))?;
-            (target_path, Some(tmp_path))
+
+            // If the target file exists, we should append to the end of it 
directly.
+            if Path::new(&target_path)
+                .try_exists()
+                .map_err(parse_io_error)?
+            {
+                (target_path, None)
+            } else {
+                (target_path, Some(tmp_path))
+            }
         } else {
             let p = Self::blocking_ensure_write_abs_path(&self.root, path)?;
 
@@ -583,14 +593,6 @@ impl Accessor for FsBackend {
 
         if op.append() {
             f.append(true);
-
-            // If the target file exists, we should append to the end of it 
directly.
-            if Path::new(&target_path)
-                .try_exists()
-                .map_err(parse_io_error)?
-            {
-                tmp_path = None;
-            }
         } else {
             f.truncate(true);
         }

Reply via email to