qorzen_oxide/platform/
filesystem.rs

1// src/platform/filesystem.rs
2
3use serde::{Deserialize, Serialize};
4use std::sync::Arc;
5
6use crate::error::Result;
7
8/// File information
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct FileInfo {
11    pub name: String,
12    pub path: String,
13    pub size: u64,
14    pub is_directory: bool,
15    pub modified: chrono::DateTime<chrono::Utc>,
16}
17
18/// File metadata
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct FileMetadata {
21    pub size: u64,
22    pub is_directory: bool,
23    pub is_readonly: bool,
24    pub created: Option<chrono::DateTime<chrono::Utc>>,
25    pub modified: chrono::DateTime<chrono::Utc>,
26    pub accessed: Option<chrono::DateTime<chrono::Utc>>,
27}
28
29#[cfg(not(target_arch = "wasm32"))]
30pub type DynFileSystem = dyn FileSystemProvider + Send + Sync;
31
32#[cfg(target_arch = "wasm32")]
33pub type DynFileSystem = dyn FileSystemProvider + Sync;
34
35pub type FileSystemArc = Arc<DynFileSystem>;
36
37/// File system operations
38#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
39#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
40pub trait FileSystemProvider: FileSystemBounds + std::fmt::Debug {
41    async fn read_file(&self, path: &str) -> Result<Vec<u8>>;
42    async fn write_file(&self, path: &str, data: &[u8]) -> Result<()>;
43    async fn delete_file(&self, path: &str) -> Result<()>;
44    async fn list_directory(&self, path: &str) -> Result<Vec<FileInfo>>;
45    async fn create_directory(&self, path: &str) -> Result<()>;
46    async fn file_exists(&self, path: &str) -> bool;
47    async fn get_metadata(&self, path: &str) -> Result<FileMetadata>;
48}
49
50#[cfg(not(target_arch = "wasm32"))]
51pub trait FileSystemBounds: Send + Sync + std::fmt::Debug {}
52
53#[cfg(target_arch = "wasm32")]
54pub trait FileSystemBounds: Sync {}