mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix 'rm' and 'rmdir' implementation on windows
This commit is contained in:
parent
8aa7da1be1
commit
c3ad75191d
21
vlib/os/os.v
21
vlib/os/os.v
@ -6,7 +6,7 @@ module os
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
//#include <unistd.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
//#include <execinfo.h> // for backtrace_symbols_fd
|
||||
|
||||
@ -347,28 +347,21 @@ pub fn mkdir(path string) {
|
||||
|
||||
// rm removes file in `path`.
|
||||
pub fn rm(path string) {
|
||||
$if windows {
|
||||
// os.system2('del /f $path')
|
||||
}
|
||||
$else {
|
||||
C.remove(path.cstr())
|
||||
}
|
||||
// C.unlink(path.cstr())
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO
|
||||
fn rmdir(path, guard string) {
|
||||
if !path.contains(guard) {
|
||||
println('rmdir canceled because the path doesnt contain $guard')
|
||||
return
|
||||
}
|
||||
|
||||
// rmdir removes a specified directory.
|
||||
pub fn rmdir(path string) {
|
||||
$if !windows {
|
||||
C.rmdir(path.cstr())
|
||||
}
|
||||
$else {
|
||||
C.RemoveDirectoryA(path.cstr())
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
fn print_c_errno() {
|
||||
//C.printf('errno=%d err="%s"\n', errno, C.strerror(errno))
|
||||
|
@ -34,9 +34,23 @@ fn test_write_and_read_string_to_file() {
|
||||
os.rm(filename)
|
||||
}
|
||||
|
||||
fn test_create_and_delete_folder() {
|
||||
folder := './test1'
|
||||
os.mkdir(folder)
|
||||
|
||||
folder_contents := os.ls(folder)
|
||||
assert folder_contents.len == 0
|
||||
|
||||
os.rmdir(folder)
|
||||
|
||||
folder_exists := os.dir_exists(folder)
|
||||
|
||||
assert folder_exists == false
|
||||
}
|
||||
|
||||
fn test_dir() {
|
||||
$if windows {
|
||||
assert os.dir('C:\a\b\c') == 'C:\a\b'
|
||||
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'
|
||||
|
||||
} $else {
|
||||
assert os.dir('/var/tmp/foo') == '/var/tmp'
|
||||
|
Loading…
Reference in New Issue
Block a user