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 <sys/stat.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
//#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
//#include <execinfo.h> // for backtrace_symbols_fd
|
//#include <execinfo.h> // for backtrace_symbols_fd
|
||||||
|
|
||||||
@ -347,28 +347,21 @@ pub fn mkdir(path string) {
|
|||||||
|
|
||||||
// rm removes file in `path`.
|
// rm removes file in `path`.
|
||||||
pub fn rm(path string) {
|
pub fn rm(path string) {
|
||||||
$if windows {
|
|
||||||
// os.system2('del /f $path')
|
|
||||||
}
|
|
||||||
$else {
|
|
||||||
C.remove(path.cstr())
|
C.remove(path.cstr())
|
||||||
}
|
|
||||||
// C.unlink(path.cstr())
|
// C.unlink(path.cstr())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO
|
// rmdir removes a specified directory.
|
||||||
fn rmdir(path, guard string) {
|
pub fn rmdir(path string) {
|
||||||
if !path.contains(guard) {
|
|
||||||
println('rmdir canceled because the path doesnt contain $guard')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
$if !windows {
|
$if !windows {
|
||||||
|
C.rmdir(path.cstr())
|
||||||
}
|
}
|
||||||
$else {
|
$else {
|
||||||
|
C.RemoveDirectoryA(path.cstr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
fn print_c_errno() {
|
fn print_c_errno() {
|
||||||
//C.printf('errno=%d err="%s"\n', errno, C.strerror(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)
|
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() {
|
fn test_dir() {
|
||||||
$if windows {
|
$if windows {
|
||||||
assert os.dir('C:\a\b\c') == 'C:\a\b'
|
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'
|
||||||
|
|
||||||
} $else {
|
} $else {
|
||||||
assert os.dir('/var/tmp/foo') == '/var/tmp'
|
assert os.dir('/var/tmp/foo') == '/var/tmp'
|
||||||
|
Loading…
Reference in New Issue
Block a user