MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / is_writable

Method is_writable

atomic-core/src/output/filesystem/mod.rs:219–236  ·  view source on GitHub ↗

Check if a path is writable. On Unix, checks the write permission bit. On Windows, checks the read-only attribute.

(&self, path: &str)

Source from the content-addressed store, hash-verified

217 /// On Unix, checks the write permission bit.
218 /// On Windows, checks the read-only attribute.
219 fn is_writable(&self, path: &str) -> Result<bool, Self::Error> {
220 let abs_path = self.resolve_path(path)?;
221
222 if !abs_path.exists() {
223 // If file doesn't exist, check if parent is writable
224 if let Some(parent) = abs_path.parent() {
225 if parent.exists() {
226 let metadata = fs::metadata(parent)?;
227 return Ok(!metadata.permissions().readonly());
228 }
229 }
230 // Assume writable if parent doesn't exist either
231 return Ok(true);
232 }
233
234 let metadata = fs::metadata(&abs_path)?;
235 Ok(!metadata.permissions().readonly())
236 }
237
238 /// Create a directory and all parent directories.
239 fn create_dir_all(&self, path: &str) -> Result<(), Self::Error> {

Callers

nothing calls this directly

Calls 4

parentMethod · 0.80
resolve_pathMethod · 0.45
existsMethod · 0.45
permissionsMethod · 0.45

Tested by

no test coverage detected