os: remove unnecessary check (#9722) (#9773)

pull/9777/head
Bastian Buck 2021-04-17 01:37:57 +02:00 committed by GitHub
parent 1b0f099552
commit 515d8c0bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 9 deletions

View File

@ -134,8 +134,9 @@ pub fn read_file(path string) ?string {
} }
// ***************************** OS ops ************************ // ***************************** OS ops ************************
//
// truncate changes the size of the file located in `path` to `len`. // truncate changes the size of the file located in `path` to `len`.
// Note that changing symbolic links on Windows only works as admin.
pub fn truncate(path string, len u64) ? { pub fn truncate(path string, len u64) ? {
fp := C.open(&char(path.str), o_wronly | o_trunc) fp := C.open(&char(path.str), o_wronly | o_trunc)
defer { defer {
@ -155,7 +156,9 @@ pub fn truncate(path string, len u64) ? {
} }
} }
// file_size returns the size of the file located in `path`. In case of error -1 is returned. // file_size returns the size of the file located in `path`.
// If an error occurs it returns 0.
// Note that use of this on symbolic links on Windows returns always 0.
pub fn file_size(path string) u64 { pub fn file_size(path string) u64 {
mut s := C.stat{} mut s := C.stat{}
unsafe { unsafe {
@ -182,7 +185,7 @@ pub fn file_size(path string) u64 {
} }
} }
} }
return -1 return 0
} }
// mv moves files or folders from `src` to `dst`. // mv moves files or folders from `src` to `dst`.
@ -868,14 +871,10 @@ pub fn chown(path string, owner int, group int) ? {
$if windows { $if windows {
return error('os.chown() not implemented for Windows') return error('os.chown() not implemented for Windows')
} $else { } $else {
if owner < 0 || group < 0 {
return error('os.chown() uid and gid cannot be negative: Not changing owner!')
} else {
if C.chown(&char(path.str), owner, group) != 0 { if C.chown(&char(path.str), owner, group) != 0 {
return error_with_code(posix_get_error_msg(C.errno), C.errno) return error_with_code(posix_get_error_msg(C.errno), C.errno)
} }
} }
}
} }
// open_append opens `path` file for appending. // open_append opens `path` file for appending.