pub struct FilePermissions {
pub read: bool,
pub write: bool,
pub execute: bool,
pub mode: Option<u32>,
}Expand description
File permission requirements and validation rules for secure file operations.
FilePermissions is a value object that encapsulates file access
permissions in a cross-platform manner, supporting both Unix-style
permission bits and Windows-style access control for comprehensive file
security management.
§Key Features
- Cross-Platform Support: Unified permission model for Unix and Windows
- Permission Validation: Ensures operations respect security constraints
- Immutable Design: Value object semantics prevent accidental modification
- Standard Presets: Common permission patterns for typical use cases
- Compatibility Checking: Validates if permissions meet requirements
§Permission Model
The permission model supports three basic access types:
- Read: Ability to read file contents
- Write: Ability to modify file contents
- Execute: Ability to execute the file (Unix) or run as program (Windows)
§Usage Patterns
§Security Considerations
- Permissions are validated before file operations
- Default permissions follow principle of least privilege
- Cross-platform compatibility ensures consistent security
- Mode bits provide fine-grained control on Unix systems
§Cross-Language Compatibility
- JSON: Object with read/write/execute boolean fields
- Go: Struct with similar field layout and os.FileMode integration
- Python: Dataclass with stat module compatibility
- Database: Separate columns for each permission type plus mode
Fields§
§read: boolWhether the file can be read
write: boolWhether the file can be written
execute: boolWhether the file can be executed
mode: Option<u32>Unix-style permission bits for fine-grained control
Implementations§
Source§impl FilePermissions
impl FilePermissions
Sourcepub fn read_only() -> Self
pub fn read_only() -> Self
Creates permissions for read-only access (0o444).
This creates a permission set that allows reading but prevents writing or executing. Suitable for configuration files, documentation, or any content that should not be modified during pipeline operations.
§Returns
A FilePermissions instance with read-only access.
§Examples
§Use Cases
- Configuration files that should not be modified
- Documentation and reference materials
- Backup files for integrity protection
- Template files used for generation
Sourcepub fn read_write() -> Self
pub fn read_write() -> Self
Creates permissions for read-write access (0o644).
This creates a permission set that allows reading and writing but prevents execution. This is the most common permission set for data files, logs, and other content that needs to be modified during pipeline operations.
§Returns
A FilePermissions instance with read-write access.
§Examples
§Use Cases
- Data files processed by the pipeline
- Log files and output files
- Temporary files during processing
- Cache files and intermediate results
Sourcepub fn full_access() -> Self
pub fn full_access() -> Self
Creates permissions for full access including execution (0o755).
This creates a permission set that allows reading, writing, and executing. Should be used sparingly and only for files that genuinely need to be executable, such as scripts or binary executables.
§Returns
A FilePermissions instance with full access.
§Examples
§Security Warning
Execute permissions should be granted carefully as they allow the file to be run as a program. Only use this for legitimate executables and scripts.
§Use Cases
- Shell scripts and batch files
- Binary executables
- Pipeline processing scripts
- Utility programs and tools
Sourcepub fn satisfies(&self, required: &FilePermissions) -> bool
pub fn satisfies(&self, required: &FilePermissions) -> bool
Validates if the current permissions satisfy the specified requirements.
This method checks whether the current permission set provides at least the access level specified in the required permissions. It uses logical AND operations to ensure all required permissions are available.
§Arguments
required- The minimum permissions that must be satisfied
§Returns
true if current permissions meet or exceed requirements, false
otherwise.
§Examples
§Logic
The satisfaction logic works as follows:
- If required.read is true, self.read must be true
- If required.write is true, self.write must be true
- If required.execute is true, self.execute must be true
- All conditions must be met for satisfaction
Trait Implementations§
Source§impl Clone for FilePermissions
impl Clone for FilePermissions
Source§fn clone(&self) -> FilePermissions
fn clone(&self) -> FilePermissions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FilePermissions
impl Debug for FilePermissions
Source§impl PartialEq for FilePermissions
impl PartialEq for FilePermissions
impl StructuralPartialEq for FilePermissions
Auto Trait Implementations§
impl Freeze for FilePermissions
impl RefUnwindSafe for FilePermissions
impl Send for FilePermissions
impl Sync for FilePermissions
impl Unpin for FilePermissions
impl UnwindSafe for FilePermissions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more