Xuanwo commented on code in PR #3098:
URL:
https://github.com/apache/incubator-opendal/pull/3098#discussion_r1328044306
##########
core/src/services/gdrive/backend.rs:
##########
@@ -253,10 +257,64 @@ impl Accessor for GdriveBackend {
GdrivePager::new(path.into(), self.core.clone()),
))
}
+
+ async fn copy(&self, from: &str, to: &str, _args: OpCopy) ->
Result<RpCopy> {
+ let from_file_id = self.core.get_file_id_by_path(from).await?;
+
+ // split `to` into parent and name according to the last `/`
+ let mut to_path_items: Vec<&str> = to.split('/').filter(|&x|
!x.is_empty()).collect();
+
+ let to_name = if let Some(name) = to_path_items.pop() {
+ name
+ } else {
+ return Err(Error::new(ErrorKind::InvalidInput, "invalid 'to'
path"));
+ };
+
+ let to_parent = to_path_items.join("/") + "/";
+
+ if to_parent != "/" {
+ self.create_dir(&to_parent, OpCreateDir::new()).await?;
+ }
+
+ let to_parent_id =
self.core.get_file_id_by_path(to_parent.as_str()).await?;
+
+ // copy will overwrite `to`, delete it if exist
+ if self.core.get_file_id_by_path(to).await.is_ok() {
+ self.delete(to, OpDelete::new()).await?;
+ }
+
+ let url = format!(
+ "https://www.googleapis.com/drive/v3/files/{}/copy",
+ from_file_id
+ );
+
+ let request_body = format!(
+ r#"{{
Review Comment:
Please use serde_json to build request instead of hand writing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]