Skip to content

Commit 5957394

Browse files
refactor(storage): Add "proper" error for remove_device_data
1 parent 5e908c8 commit 5957394

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

libparsec/crates/client/src/device/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
22

33
use libparsec_platform_device_loader::AvailableDevice;
4-
use libparsec_types::prelude::*;
4+
use libparsec_platform_storage::RemoveDeviceDataError;
55

66
use crate::ClientConfig;
77

@@ -10,7 +10,7 @@ pub enum RemoveDeviceError {
1010
#[error("Failed to remove device: {}", .0)]
1111
DeviceRemovalError(libparsec_platform_device_loader::RemoveDeviceError),
1212
#[error("Failed to remove device data: {}", .0)]
13-
DeviceDataRemovalError(anyhow::Error),
13+
DeviceDataRemovalError(RemoveDeviceDataError),
1414
}
1515

1616
/// Remove device from existence.

libparsec/crates/platform_storage/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ pub(crate) use web as platform;
1313
pub mod certificates;
1414
pub mod user;
1515
pub mod workspace;
16+
17+
#[derive(Debug, thiserror::Error)]
18+
pub enum RemoveDeviceDataError {
19+
#[error("Failed to remove data: {0}")]
20+
FailedToRemoveData(#[from] libparsec_types::anyhow::Error),
21+
}
22+
1623
pub use platform::cleanup::remove_device_data;
1724

1825
// Testbed integration is tested in the `libparsec_tests_fixture` crate.

libparsec/crates/platform_storage/src/native/cleanup.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ use std::path::Path;
44

55
use libparsec_types::{anyhow, DeviceID};
66

7-
pub async fn remove_device_data(data_base_dir: &Path, device_id: DeviceID) -> anyhow::Result<()> {
7+
pub async fn remove_device_data(
8+
data_base_dir: &Path,
9+
device_id: DeviceID,
10+
) -> Result<(), crate::RemoveDeviceDataError> {
811
let path = data_base_dir.join(device_id.hex());
912
log::debug!("Removing device data at {}", path.display());
1013

1114
tokio::fs::remove_dir_all(&path)
1215
.await
1316
.map_err(anyhow::Error::from)
17+
.map_err(Into::into)
1418
}
1519

1620
#[cfg(test)]

libparsec/crates/platform_storage/src/web/cleanup.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ async fn drop_db(name: &str) -> anyhow::Result<()> {
1414
.map_err(anyhow::Error::from)
1515
}
1616

17-
pub async fn remove_device_data(data_base_dir: &Path, device_id: DeviceID) -> anyhow::Result<()> {
17+
pub async fn remove_device_data(
18+
data_base_dir: &Path,
19+
device_id: DeviceID,
20+
) -> Result<(), crate::RemoveDeviceDataError> {
1821
drop_db(&get_certificates_storage_db_name(data_base_dir, device_id)).await?;
1922
drop_db(&get_user_storage_db_name(data_base_dir, device_id)).await?;
2023

0 commit comments

Comments
 (0)