Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
liugddx committed Sep 11, 2024
1 parent 74ec9d5 commit d027265
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
12 changes: 12 additions & 0 deletions core/src/services/lakefs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl Access for LakefsBackend {
read: true,
write: true,
delete: true,
copy: true,
..Default::default()
});
am.into()
Expand Down Expand Up @@ -302,4 +303,15 @@ impl Access for LakefsBackend {
_ => Err(parse_error(resp).await?),
}
}

async fn copy(&self, from: &str, to: &str, _args: OpCopy) -> Result<RpCopy> {
let resp = self.core.copy_object(from, to).await?;

let status = resp.status();

match status {
StatusCode::CREATED => Ok(RpCopy::default()),
_ => Err(parse_error(resp).await?),
}
}
}
35 changes: 33 additions & 2 deletions core/src/services/lakefs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// specific language governing permissions and limitations
// under the License.

use std::fmt::Debug;

use http::header;
use http::Request;
use http::Response;
use serde::Deserialize;
use std::collections::HashMap;
use std::fmt::Debug;

use crate::raw::*;
use crate::*;
Expand Down Expand Up @@ -194,6 +194,37 @@ impl LakefsCore {

self.client.send(req).await
}

pub async fn copy_object(&self, path: &str, dest: &str) -> Result<Response<Buffer>> {
let p = build_abs_path(&self.root, path)
.trim_end_matches('/')
.to_string();
let d = build_abs_path(&self.root, dest)
.trim_end_matches('/')
.to_string();

let url = format!(
"{}/api/v1/repositories/{}/branches/{}/objects/copy?dest_path={}",
self.endpoint,
self.repository,
self.branch,
percent_encode_path(&d)
);

let mut req = Request::post(&url);

let auth_header_content = format_authorization_by_basic(&self.username, &self.password)?;
req = req.header(header::AUTHORIZATION, auth_header_content);
req = req.header(header::CONTENT_TYPE, "application/json");
let mut map = HashMap::new();
map.insert("src_path", p);

let req = req
.body(serde_json::to_vec(&map).unwrap().into())
.map_err(new_request_build_error)?;

self.client.send(req).await
}
}

#[derive(Deserialize, Eq, PartialEq, Debug)]
Expand Down

0 comments on commit d027265

Please sign in to comment.