Expand description
Secure file system operations and management Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of DMSC. The DMSC project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§File System Module
This module provides a comprehensive file system abstraction for DMSC, offering safe and reliable file operations with support for atomic writes, directory management, and structured data formats.
§Key Components
- DMSCFileSystem: Public-facing file system class
- FileSystemImpl: Internal file system implementation
§Design Principles
- Safe Operations: All file operations are designed to be safe and reliable
- Atomic Writes: Uses atomic write operations to prevent data corruption
- Directory Management: Automatically creates necessary directories
- Structured Data Support: Built-in support for JSON serialization and deserialization
- Category-Based Organization: Organizes files into categories (logs, cache, reports, etc.)
- Error Handling: Provides comprehensive error handling for all file operations
- Cloneable: Designed to be easily cloned for use across different components
§Usage
use dmsc::prelude::*;
use std::path::PathBuf;
fn example() -> DMSCResult<()> {
// Create a file system with a project root
let project_root = PathBuf::from(".");
let fs = DMSCFileSystem::new_with_root(project_root);
// Write text to a file
fs.atomic_write_text("example.txt", "Hello, DMSC!")?;
// Read text from a file
let content = fs.read_text("example.txt")?;
println!("File content: {}", content);
// Write JSON to a file
let data = json!({"key": "value"});
fs.write_json("example.json", &data)?;
// Read JSON from a file
let read_data: serde_json::Value = fs.read_json("example.json")?;
println!("JSON data: {:?}", read_data);
// Get category directories
let logs_dir = fs.logs_dir();
println!("Logs directory: {:?}", logs_dir);
Ok(())
}Structs§
- DMSC
File System - Public-facing filesystem class.