Skip to content

Commit

Permalink
feat(adapters-kv): fix code
Browse files Browse the repository at this point in the history
Signed-off-by: owl <ouyangjun1999@gmail.com>
  • Loading branch information
oowl committed Jun 23, 2023
1 parent 1c884db commit 251c5b5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 32 deletions.
42 changes: 26 additions & 16 deletions core/src/raw/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,35 @@ impl<S: Adapter> Accessor for Backend<S> {
}

async fn rename(&self, from: &str, to: &str, _: OpRename) -> Result<RpRename> {
match self.copy(from, to, OpCopy {}).await {
Ok(_) => {
let from = build_abs_path(&self.root, from);
self.kv.delete(&from).await?;
Ok(RpRename::default())
}
Err(e) => Err(e),
}
let from = build_abs_path(&self.root, from);
let to = build_abs_path(&self.root, to);

let bs = match self.kv.get(&from).await? {
// TODO: we can reuse the metadata in value to build content range.
Some(bs) => bs,
None => return Err(Error::new(ErrorKind::NotFound, "kv doesn't have this path")),
};

self.kv.set(&to, &bs).await?;

self.kv.delete(&from).await?;
Ok(RpRename::default())
}

fn blocking_rename(&self, from: &str, to: &str, _: OpRename) -> Result<RpRename> {
match self.blocking_copy(from, to, OpCopy {}) {
Ok(_) => {
let from = build_abs_path(&self.root, from);
self.kv.blocking_delete(&from)?;
Ok(RpRename::default())
}
Err(e) => Err(e),
}
let from = build_abs_path(&self.root, from);
let to = build_abs_path(&self.root, to);

let bs = match self.kv.blocking_get(&from)? {
// TODO: we can reuse the metadata in value to build content range.
Some(bs) => bs,
None => return Err(Error::new(ErrorKind::NotFound, "kv doesn't have this path")),
};

self.kv.blocking_set(&to, &bs)?;

self.kv.blocking_delete(&from)?;
Ok(RpRename::default())
}

async fn copy(&self, from: &str, to: &str, _: OpCopy) -> Result<RpCopy> {
Expand Down
40 changes: 24 additions & 16 deletions core/src/raw/adapters/typed_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,33 @@ impl<S: Adapter> Accessor for Backend<S> {
}

async fn rename(&self, from: &str, to: &str, _: OpRename) -> Result<RpRename> {
match self.copy(from, to, OpCopy {}).await {
Ok(_) => {
let from = build_abs_path(&self.root, from);
self.kv.delete(&from).await?;
Ok(RpRename::default())
}
Err(e) => Err(e),
}
let from = build_abs_path(&self.root, from);
let to = build_abs_path(&self.root, to);

let bs = match self.kv.get(&from).await? {
// TODO: we can reuse the metadata in value to build content range.
Some(bs) => bs,
None => return Err(Error::new(ErrorKind::NotFound, "kv doesn't have this path")),
};

self.kv.set(&to, bs).await?;
self.kv.delete(&from).await?;
Ok(RpRename::default())
}

fn blocking_rename(&self, from: &str, to: &str, _: OpRename) -> Result<RpRename> {
match self.blocking_copy(from, to, OpCopy {}) {
Ok(_) => {
let from = build_abs_path(&self.root, from);
self.kv.blocking_delete(&from)?;
Ok(RpRename::default())
}
Err(e) => Err(e),
}
let from = build_abs_path(&self.root, from);
let to = build_abs_path(&self.root, to);

let bs = match self.kv.blocking_get(&from)? {
// TODO: we can reuse the metadata in value to build content range.
Some(bs) => bs,
None => return Err(Error::new(ErrorKind::NotFound, "kv doesn't have this path")),
};

self.kv.blocking_set(&to, bs)?;
self.kv.blocking_delete(&from)?;
Ok(RpRename::default())
}

async fn copy(&self, from: &str, to: &str, _: OpCopy) -> Result<RpCopy> {
Expand Down

0 comments on commit 251c5b5

Please sign in to comment.