Datasets:
Tasks:
Text Generation
Formats:
parquet
Sub-tasks:
language-modeling
Languages:
English
Size:
< 1K
License:
Download harbor/sources/rust-postgres-v6/task/gold.diff from ExpertCrowd/ec-swe: direct link, hf CLI and curl.
- Browser
- Download file 5.87 kB
-
https://huggingface.co/datasets/ExpertCrowd/ec-swe/resolve/main/harbor/sources/rust-postgres-v6/task/gold.diff
- Command line
-
hf download hf://datasets/ExpertCrowd/ec-swe/harbor/sources/rust-postgres-v6/task/gold.diff
-
curl -L -o gold.diff https://huggingface.co/datasets/ExpertCrowd/ec-swe/resolve/main/harbor/sources/rust-postgres-v6/task/gold.diff
5.87 kB
| diff --git a/tokio-postgres/src/bind.rs b/tokio-postgres/src/bind.rs | |
| index 06cd14d2..ac1a4f90 100644 | |
| --- a/tokio-postgres/src/bind.rs | |
| +++ b/tokio-postgres/src/bind.rs | |
| use std::sync::atomic::{AtomicUsize, Ordering}; | |
| static NEXT_ID: AtomicUsize = AtomicUsize::new(0); | |
| +/// Closes the named portal on the server if the `bind` future is dropped before | |
| +/// the `Portal` handle (whose own `Drop` performs the close) has been constructed. | |
| +struct CloseOnDrop<'a> { | |
| + client: &'a Arc<InnerClient>, | |
| + name: Option<String>, | |
| +} | |
| + | |
| +impl CloseOnDrop<'_> { | |
| + fn disarm(mut self) -> String { | |
| + self.name.take().expect("guard already disarmed") | |
| + } | |
| +} | |
| + | |
| +impl Drop for CloseOnDrop<'_> { | |
| + fn drop(&mut self) { | |
| + if let Some(name) = self.name.take() { | |
| + let buf = self.client.with_buf(|buf| { | |
| + frontend::close(b'P', &name, buf).unwrap(); | |
| + frontend::sync(buf); | |
| + buf.split().freeze() | |
| + }); | |
| + let _ = self | |
| + .client | |
| + .send(RequestMessages::Single(FrontendMessage::Raw(buf))); | |
| + } | |
| + } | |
| +} | |
| + | |
| pub async fn bind<P, I>( | |
| client: &Arc<InnerClient>, | |
| statement: Statement, | |
| where | |
| })?; | |
| let mut responses = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)))?; | |
| + let guard = CloseOnDrop { | |
| + client, | |
| + name: Some(name), | |
| + }; | |
| match responses.next().await? { | |
| Message::BindComplete => {} | |
| _ => return Err(Error::unexpected_message()), | |
| } | |
| - Ok(Portal::new(client, name, statement)) | |
| + Ok(Portal::new(client, guard.disarm(), statement)) | |
| } | |
| diff --git a/tokio-postgres/src/client.rs b/tokio-postgres/src/client.rs | |
| index 6d3b03d3..e4136665 100644 | |
| --- a/tokio-postgres/src/client.rs | |
| +++ b/tokio-postgres/src/client.rs | |
| impl Client { | |
| .send(RequestMessages::Single(FrontendMessage::Raw(buf))); | |
| } | |
| + #[doc(hidden)] | |
| + pub fn __private_api_release_savepoint(&self, name: &str) { | |
| + let buf = self.inner().with_buf(|buf| { | |
| + frontend::query(&format!("RELEASE {name}"), buf).unwrap(); | |
| + buf.split().freeze() | |
| + }); | |
| + let _ = self | |
| + .inner() | |
| + .send(RequestMessages::Single(FrontendMessage::Raw(buf))); | |
| + } | |
| + | |
| #[doc(hidden)] | |
| pub fn __private_api_close(&mut self) { | |
| self.inner.sender.close_channel() | |
| diff --git a/tokio-postgres/src/prepare.rs b/tokio-postgres/src/prepare.rs | |
| index 8484fa33..ad673a4c 100644 | |
| --- a/tokio-postgres/src/prepare.rs | |
| +++ b/tokio-postgres/src/prepare.rs | |
| ORDER BY attnum | |
| static NEXT_ID: AtomicUsize = AtomicUsize::new(0); | |
| +/// Closes the named statement on the server if the `prepare` future is dropped | |
| +/// before the `Statement` handle (whose own `Drop` performs the close) has been | |
| +/// constructed. | |
| +struct CloseOnDrop<'a> { | |
| + client: &'a Arc<InnerClient>, | |
| + name: Option<String>, | |
| +} | |
| + | |
| +impl CloseOnDrop<'_> { | |
| + fn disarm(mut self) -> String { | |
| + self.name.take().expect("guard already disarmed") | |
| + } | |
| +} | |
| + | |
| +impl Drop for CloseOnDrop<'_> { | |
| + fn drop(&mut self) { | |
| + if let Some(name) = self.name.take() { | |
| + let buf = self.client.with_buf(|buf| { | |
| + frontend::close(b'S', &name, buf).unwrap(); | |
| + frontend::sync(buf); | |
| + buf.split().freeze() | |
| + }); | |
| + let _ = self | |
| + .client | |
| + .send(RequestMessages::Single(FrontendMessage::Raw(buf))); | |
| + } | |
| + } | |
| +} | |
| + | |
| pub async fn prepare( | |
| client: &Arc<InnerClient>, | |
| query: &str, | |
| pub async fn prepare( | |
| let name = format!("s{}", NEXT_ID.fetch_add(1, Ordering::SeqCst)); | |
| let buf = encode(client, &name, query, types)?; | |
| let mut responses = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)))?; | |
| + // From this point on the server may own a statement named `name`; make sure | |
| + // it is closed if this future is abandoned before `Statement` takes over. | |
| + let guard = CloseOnDrop { | |
| + client, | |
| + name: Some(name), | |
| + }; | |
| match responses.next().await? { | |
| Message::ParseComplete => {} | |
| pub async fn prepare( | |
| } | |
| } | |
| - Ok(Statement::new(client, name, parameters, columns)) | |
| + Ok(Statement::new(client, guard.disarm(), parameters, columns)) | |
| } | |
| fn prepare_rec<'a>( | |
| diff --git a/tokio-postgres/src/transaction.rs b/tokio-postgres/src/transaction.rs | |
| index 81e8036b..d901764e 100644 | |
| --- a/tokio-postgres/src/transaction.rs | |
| +++ b/tokio-postgres/src/transaction.rs | |
| impl<'a> Transaction<'a> { | |
| let depth = self.savepoint.as_ref().map_or(0, |sp| sp.depth) + 1; | |
| let name = name.unwrap_or_else(|| format!("sp_{depth}")); | |
| let query = format!("SAVEPOINT {name}"); | |
| - self.batch_execute(&query).await?; | |
| + | |
| + struct ReleaseIfNotDone<'me> { | |
| + client: &'me Client, | |
| + name: &'me str, | |
| + done: bool, | |
| + } | |
| + | |
| + impl Drop for ReleaseIfNotDone<'_> { | |
| + fn drop(&mut self) { | |
| + if self.done { | |
| + return; | |
| + } | |
| + | |
| + // The future was dropped after `SAVEPOINT` was sent but before the | |
| + // nested `Transaction` (which would roll it back on drop) was created. | |
| + self.client.__private_api_release_savepoint(self.name); | |
| + } | |
| + } | |
| + | |
| + { | |
| + let mut cleaner = ReleaseIfNotDone { | |
| + client: self.client, | |
| + name: &name, | |
| + done: false, | |
| + }; | |
| + self.client.batch_execute(&query).await?; | |
| + cleaner.done = true; | |
| + } | |
| Ok(Transaction { | |
| client: self.client, | |