mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-08 07:12:49 +00:00
[ENG-333] Handle .spacedrive existing instead of throwing error (#521)
* Removing metadata files that failed to be deserialized * Reintroducing deserialize error for location metadata on prod builds
This commit is contained in:
parent
1a1ddf3409
commit
31d04d5594
|
@ -7,6 +7,7 @@ use chrono::{DateTime, Utc};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use tokio::{fs, io};
|
||||
use tracing::error;
|
||||
use uuid::Uuid;
|
||||
|
||||
static SPACEDRIVE_LOCATION_METADATA_FILE: &str = ".spacedrive";
|
||||
|
@ -45,10 +46,34 @@ impl SpacedriveLocationMetadataFile {
|
|||
|
||||
match fs::read(&metadata_file_name).await {
|
||||
Ok(data) => Ok(Some(Self {
|
||||
metadata: match serde_json::from_slice(&data) {
|
||||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
error!(
|
||||
"Failed to deserialize corrupted metadata file, \
|
||||
we will remove it and create a new one; File: {}; Error: {e}",
|
||||
metadata_file_name.display()
|
||||
);
|
||||
fs::remove_file(&metadata_file_name).await.map_err(|e| {
|
||||
LocationMetadataError::Delete(
|
||||
e,
|
||||
location_path.as_ref().to_path_buf(),
|
||||
)
|
||||
})?;
|
||||
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
return Err(LocationMetadataError::Deserialize(
|
||||
e,
|
||||
location_path.as_ref().to_path_buf(),
|
||||
));
|
||||
}
|
||||
},
|
||||
path: metadata_file_name,
|
||||
metadata: serde_json::from_slice(&data).map_err(|e| {
|
||||
LocationMetadataError::Deserialize(e, location_path.as_ref().to_path_buf())
|
||||
})?,
|
||||
})),
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(None),
|
||||
Err(e) => Err(LocationMetadataError::Read(
|
||||
|
|
|
@ -216,9 +216,11 @@ impl StatefulJob for FileEncryptorJob {
|
|||
.find_unique(object::id::equals(obj_id))
|
||||
.exec()
|
||||
.await?
|
||||
.ok_or(JobError::JobDataNotFound(String::from(
|
||||
"can't find information about the object",
|
||||
)))?;
|
||||
.ok_or_else(|| {
|
||||
JobError::JobDataNotFound(String::from(
|
||||
"can't find information about the object",
|
||||
))
|
||||
})?;
|
||||
|
||||
if state.init.metadata {
|
||||
let metadata = Metadata {
|
||||
|
|
Loading…
Reference in a new issue