mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-18 05:30:37 +00:00
half-baked copy_file impl
This commit is contained in:
committed by
Christian Schwarz
parent
18ec49843b
commit
f5a5f0bce8
@@ -353,4 +353,8 @@ impl RemoteStorage for AzureBlobStorage {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn copy_object(&self, src: &RemotePath, dst: &RemotePath) -> anyhow::Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ impl RemotePath {
|
||||
self.0.file_name()
|
||||
}
|
||||
|
||||
pub fn join(&self, segment: &Utf8Path) -> Self {
|
||||
pub fn join<P: AsRef<Utf8Path>>(&self, segment: P) -> Self {
|
||||
Self(self.0.join(segment))
|
||||
}
|
||||
|
||||
@@ -183,6 +183,8 @@ pub trait RemoteStorage: Send + Sync + 'static {
|
||||
async fn delete(&self, path: &RemotePath) -> anyhow::Result<()>;
|
||||
|
||||
async fn delete_objects<'a>(&self, paths: &'a [RemotePath]) -> anyhow::Result<()>;
|
||||
|
||||
async fn copy_object(&self, src: &RemotePath, dst: &RemotePath) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
pub struct Download {
|
||||
@@ -328,6 +330,15 @@ impl GenericRemoteStorage {
|
||||
Self::Unreliable(s) => s.delete_objects(paths).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn copy_object(&self, src: &RemotePath, dst: &RemotePath) -> anyhow::Result<()> {
|
||||
match self {
|
||||
Self::LocalFs(s) => s.copy_object(src, dst).await,
|
||||
Self::AwsS3(s) => s.copy_object(src, dst).await,
|
||||
Self::AzureBlob(s) => s.copy_object(src, dst).await,
|
||||
Self::Unreliable(s) => s.copy_object(src, dst).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GenericRemoteStorage {
|
||||
|
||||
@@ -371,6 +371,27 @@ impl RemoteStorage for LocalFs {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn copy_object(&self, src: &RemotePath, dst: &RemotePath) -> anyhow::Result<()> {
|
||||
let src_path = src.with_base(&self.storage_root);
|
||||
let dst_path = dst.with_base(&self.storage_root);
|
||||
|
||||
// If the destination file already exists, we need to delete it first.
|
||||
if dst_path.exists() {
|
||||
fs::remove_file(&dst_path).await?;
|
||||
}
|
||||
|
||||
// Copy the file.
|
||||
fs::copy(&src_path, &dst_path).await?;
|
||||
|
||||
// Copy the metadata.
|
||||
let metadata_path = storage_metadata_path(&src_path);
|
||||
if metadata_path.exists() {
|
||||
fs::copy(&metadata_path, storage_metadata_path(&dst_path)).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn storage_metadata_path(original_path: &Utf8Path) -> Utf8PathBuf {
|
||||
|
||||
@@ -221,6 +221,8 @@ impl S3Bucket {
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
pin_project_lite::pin_project! {
|
||||
@@ -546,6 +548,11 @@ impl RemoteStorage for S3Bucket {
|
||||
let paths = std::array::from_ref(path);
|
||||
self.delete_objects(paths).await
|
||||
}
|
||||
|
||||
async fn copy_object(&self, src: &RemotePath, dst: &RemotePath) -> anyhow::Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// On drop (cancellation) count towards [`metrics::BucketMetrics::cancelled_waits`].
|
||||
@@ -628,4 +635,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -149,4 +149,8 @@ impl RemoteStorage for UnreliableWrapper {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn copy_object(&self, src: &RemotePath, dst: &RemotePath) -> anyhow::Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user