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:
17
vlib/os/os.v
17
vlib/os/os.v
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user