mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-19 05:45:01 -04:00
Hide .spacedrive file on Windows (#2216)
* Hide `.spacedrive` file on Windows * Use hard-coded hidden file attribute * Remove winapi crate * fix: use `?` operator instead of `unwrap` --------- Co-authored-by: jake <77554505+brxken128@users.noreply.github.com>
This commit is contained in:
@@ -8,7 +8,10 @@ use std::{
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use tokio::{fs, io};
|
||||
use tokio::{
|
||||
fs::{self, OpenOptions},
|
||||
io::{self, AsyncWriteExt},
|
||||
};
|
||||
use tracing::error;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -247,13 +250,28 @@ impl SpacedriveLocationMetadataFile {
|
||||
}
|
||||
|
||||
async fn write_metadata(&self) -> Result<(), LocationMetadataError> {
|
||||
fs::write(
|
||||
&self.path,
|
||||
serde_json::to_vec(&self.metadata)
|
||||
.map_err(|e| LocationMetadataError::Serialize(e, self.path.clone()))?,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| LocationMetadataError::Write(e, self.path.clone()))
|
||||
let mut file_options = OpenOptions::new();
|
||||
|
||||
// we want to write the file if it exists, otherwise create it
|
||||
file_options.create(true).write(true);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let FILE_ATTRIBUTE_HIDDEN = 0x00000002; // Windows file attribute byte indicating hidden file
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
file_options.attributes(FILE_ATTRIBUTE_HIDDEN);
|
||||
}
|
||||
|
||||
let metadata_contents = serde_json::to_vec(&self.metadata)
|
||||
.map_err(|e| LocationMetadataError::Serialize(e, self.path.clone()))?;
|
||||
|
||||
file_options
|
||||
.open(&self.path)
|
||||
.await
|
||||
.map_err(|e| LocationMetadataError::Write(e, self.path.clone()))?
|
||||
.write_all(&metadata_contents)
|
||||
.await
|
||||
.map_err(|e| LocationMetadataError::Write(e, self.path.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user