From a12ecd53bd5d484cf7c4cb25a4cec6f927cc8505 Mon Sep 17 00:00:00 2001 From: meteorgan Date: Sun, 25 Aug 2024 02:44:53 +0800 Subject: [PATCH] fix append logic --- core/src/services/hdfs/backend.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/services/hdfs/backend.rs b/core/src/services/hdfs/backend.rs index 435a4231053a..754bef088212 100644 --- a/core/src/services/hdfs/backend.rs +++ b/core/src/services/hdfs/backend.rs @@ -300,9 +300,10 @@ impl Access for HdfsBackend { } }; + let should_append = op.append() && target_exists; let tmp_path = self.atomic_write_dir.as_ref().and_then(|atomic_write_dir| { // If the target file exists, we should append to the end of it directly. - if op.append() && target_exists { + if should_append { None } else { Some(build_rooted_abs_path(atomic_write_dir, &tmp_file_of(path))) @@ -321,7 +322,7 @@ impl Access for HdfsBackend { let mut open_options = self.client.open_file(); open_options.create(true); - if op.append() { + if should_append { open_options.append(true); } else { open_options.write(true); @@ -493,9 +494,10 @@ impl Access for HdfsBackend { } }; + let should_append = op.append() && target_exists; let tmp_path = self.atomic_write_dir.as_ref().and_then(|atomic_write_dir| { // If the target file exists, we should append to the end of it directly. - if op.append() && target_exists { + if should_append { None } else { Some(build_rooted_abs_path(atomic_write_dir, &tmp_file_of(path))) @@ -514,7 +516,7 @@ impl Access for HdfsBackend { let mut open_options = self.client.open_file(); open_options.create(true); - if op.append() { + if should_append { open_options.append(true); } else { open_options.write(true);