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 f05b94c9ba fix(bindings/python): missed to call close for the file
internally (#4122)
f05b94c9ba is described below
commit f05b94c9badd2922903257b6905ab1f805ec34ab
Author: JimZhang <[email protected]>
AuthorDate: Thu Feb 1 17:13:43 2024 +0800
fix(bindings/python): missed to call close for the file internally (#4122)
* fix(bindings/python): missed to call close for the file internally (#4120)
* style: cargo fmt
* style: clippy check
---
bindings/python/src/file.rs | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs
index 304bb0f312..b7db1997d5 100644
--- a/bindings/python/src/file.rs
+++ b/bindings/python/src/file.rs
@@ -176,6 +176,10 @@ impl File {
}
fn close(&mut self) -> PyResult<()> {
+ if let FileState::Writer(w) = &mut self.0 {
+ w.close()
+ .map_err(|err| PyIOError::new_err(err.to_string()))?;
+ };
self.0 = FileState::Closed;
Ok(())
}
@@ -185,7 +189,7 @@ impl File {
}
pub fn __exit__(&mut self, _exc_type: PyObject, _exc_value: PyObject,
_traceback: PyObject) {
- self.0 = FileState::Closed;
+ let _ = self.close();
}
}
@@ -361,6 +365,11 @@ impl AsyncFile {
let state = self.0.clone();
future_into_py(py, async move {
let mut state = state.lock().await;
+ if let AsyncFileState::Writer(w) = &mut *state {
+ w.close()
+ .await
+ .map_err(|err| PyIOError::new_err(err.to_string()))?;
+ }
*state = AsyncFileState::Closed;
Ok(())
})
@@ -381,6 +390,11 @@ impl AsyncFile {
let state = self.0.clone();
future_into_py(py, async move {
let mut state = state.lock().await;
+ if let AsyncFileState::Writer(w) = &mut *state {
+ w.close()
+ .await
+ .map_err(|err| PyIOError::new_err(err.to_string()))?;
+ }
*state = AsyncFileState::Closed;
Ok(())
})