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

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 5bc5a25507 fix(services/compfs): avoid opening file when aborting 
unused writer (#8756)
5bc5a25507 is described below

commit 5bc5a25507b6c6ef401cba881cde6117ef32e0ce
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 07:50:55 2026 +0800

    fix(services/compfs): avoid opening file when aborting unused writer (#8756)
    
    CompfsLazyWriter::abort() called inner() unconditionally, which opened the 
target with truncate before returning Unsupported. That truncated an existing 
file or created the target and its parent directories. Return Unsupported 
directly when the writer was never initialized.
---
 core/services/compfs/src/reader.rs | 50 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/core/services/compfs/src/reader.rs 
b/core/services/compfs/src/reader.rs
index 30114d886d..d7c90b178f 100644
--- a/core/services/compfs/src/reader.rs
+++ b/core/services/compfs/src/reader.rs
@@ -154,7 +154,13 @@ impl oio::Write for CompfsLazyWriter {
     }
 
     async fn abort(&mut self) -> Result<()> {
-        self.inner().await?.abort().await
+        match &mut self.inner {
+            Some(w) => w.abort().await,
+            None => Err(Error::new(
+                ErrorKind::Unsupported,
+                "cannot abort completion-based operations",
+            )),
+        }
     }
 }
 
@@ -200,3 +206,45 @@ impl oio::List for CompfsLazyLister {
         }
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use opendal_core::ErrorKind;
+    use opendal_core::Operator;
+
+    use crate::Compfs;
+
+    #[tokio::test]
+    async fn test_abort_unused_writer_preserves_existing_file() {
+        let root = 
std::env::temp_dir().join("opendal-test-compfs-abort-unused-existing");
+        let _ = std::fs::remove_dir_all(&root);
+        std::fs::create_dir_all(&root).unwrap();
+        let path = root.join("existing.txt");
+        std::fs::write(&path, b"original").unwrap();
+
+        let op = 
Operator::new(Compfs::default().root(root.to_str().unwrap())).unwrap();
+        let mut writer = op.writer("existing.txt").await.unwrap();
+
+        let err = writer.abort().await.unwrap_err();
+        assert_eq!(err.kind(), ErrorKind::Unsupported);
+        assert_eq!(std::fs::read(&path).unwrap(), b"original");
+
+        std::fs::remove_dir_all(&root).unwrap();
+    }
+
+    #[tokio::test]
+    async fn test_abort_unused_writer_does_not_create_path() {
+        let root = 
std::env::temp_dir().join("opendal-test-compfs-abort-unused-missing");
+        let _ = std::fs::remove_dir_all(&root);
+        std::fs::create_dir_all(&root).unwrap();
+
+        let op = 
Operator::new(Compfs::default().root(root.to_str().unwrap())).unwrap();
+        let mut writer = op.writer("new-dir/nested/file.txt").await.unwrap();
+
+        let err = writer.abort().await.unwrap_err();
+        assert_eq!(err.kind(), ErrorKind::Unsupported);
+        assert!(!root.join("new-dir").exists());
+
+        std::fs::remove_dir_all(&root).unwrap();
+    }
+}

Reply via email to