1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: implement os.is_writable_folder/1

This commit is contained in:
Delyan Angelov
2020-04-05 16:56:54 +03:00
parent f139e98745
commit 206c1f4ca1
2 changed files with 26 additions and 0 deletions

View File

@@ -543,6 +543,23 @@ pub fn is_executable(path string) bool {
return C.access(path.str, X_OK) != -1
}
// `is_writable_folder` - `folder` exists and is writable to the process
pub fn is_writable_folder(folder string) ?bool {
if !os.exists(folder) {
return error('`$folder` does not exist')
}
if !os.is_dir(folder) {
return error('`folder` is not a folder')
}
tmp_perm_check := os.join_path(folder, 'tmp_perm_check')
f := os.open_file(tmp_perm_check, 'w+', 0o700) or {
return error('cannot write to folder `$folder`: $err')
}
f.close()
os.rm(tmp_perm_check)
return true
}
// `is_writable` returns `true` if `path` is writable.
pub fn is_writable(path string) bool {
$if windows {