os: implement os.is_writable_folder/1
parent
f139e98745
commit
206c1f4ca1
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 {
|
||||
|
|
|
@ -208,6 +208,15 @@ fn test_tmpdir() {
|
|||
os.rm(tfile)
|
||||
}
|
||||
|
||||
fn test_is_writable_folder() {
|
||||
tmp := os.temp_dir()
|
||||
f := os.is_writable_folder(tmp) or {
|
||||
eprintln('err: $err')
|
||||
assert false
|
||||
}
|
||||
assert f
|
||||
}
|
||||
|
||||
fn test_make_symlink_check_is_link_and_remove_symlink() {
|
||||
$if windows {
|
||||
// TODO
|
||||
|
|
Loading…
Reference in New Issue