Skip to content

Commit

Permalink
fix(services/aliyun-drive): write op cannot overwrite existing files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchanns authored Jun 21, 2024
1 parent 8027430 commit cf7580e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/services/aliyun_drive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impl Builder for AliyunDriveBuilder {
sign,
})),
client,
dir_lock: Arc::new(Mutex::new(())),
}),
})
}
Expand Down Expand Up @@ -462,6 +463,17 @@ impl Access for AliyunDriveBackend {
let parent_path = get_parent(path);
let parent_file_id = self.core.ensure_dir_exists(parent_path).await?;

// write can overwrite
match self.core.get_by_path(path).await {
Err(err) if err.kind() == ErrorKind::NotFound => {}
Err(err) => return Err(err),
Ok(res) => {
let file: AliyunDriveFile =
serde_json::from_reader(res.reader()).map_err(new_json_serialize_error)?;
self.core.delete_path(&file.file_id).await?;
}
};

let executor = args.executor().cloned();

let writer =
Expand Down
2 changes: 2 additions & 0 deletions core/src/services/aliyun_drive/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct AliyunDriveCore {

pub signer: Arc<Mutex<AliyunDriveSigner>>,
pub client: HttpClient,
pub dir_lock: Arc<Mutex<()>>,
}

impl Debug for AliyunDriveCore {
Expand Down Expand Up @@ -210,6 +211,7 @@ impl AliyunDriveCore {
let paths = file_path.split('/').collect::<Vec<&str>>();
let mut parent: Option<String> = None;
for path in paths {
let _guard = self.dir_lock.lock().await;
let res = self
.create(
parent.as_deref(),
Expand Down

0 comments on commit cf7580e

Please sign in to comment.