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

Method is_writable

atomic-core/src/output/filesystem/mod.rs:241–258  ·  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

239 /// On Unix, checks the write permission bit.
240 /// On Windows, checks the read-only attribute.
241 fn is_writable(&self, path: &str) -> Result<bool, Self::Error> {
242 let abs_path = self.resolve_path(path)?;
243
244 if !abs_path.exists() {
245 // If file doesn't exist, check if parent is writable
246 if let Some(parent) = abs_path.parent() {
247 if parent.exists() {
248 let metadata = fs::metadata(parent)?;
249 return Ok(!metadata.permissions().readonly());
250 }
251 }
252 // Assume writable if parent doesn't exist either
253 return Ok(true);
254 }
255
256 let metadata = fs::metadata(&abs_path)?;
257 Ok(!metadata.permissions().readonly())
258 }
259
260 /// Create a directory and all parent directories.
261 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