1
0
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:
Ned Palacios 2019-07-16 21:55:51 +08:00 committed by Alexander Medvednikov
parent 8aa7da1be1
commit c3ad75191d
2 changed files with 22 additions and 15 deletions

View File

@ -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))

View File

@ -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'