1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: return the long path for os.temp_dir() on windows, even for folders like c:\someth~1 (#17623)

This commit is contained in:
Delyan Angelov 2023-03-14 00:51:52 +02:00 committed by GitHub
parent d1d26893f5
commit daa9034583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 1 deletions

View File

@ -716,6 +716,7 @@ pub fn temp_dir() string {
path = 'C:/tmp'
}
}
path = get_long_path(path) or { path }
}
$if macos {
// avoid /var/folders/6j/cmsk8gd90pd.... on macs

View File

@ -183,3 +183,9 @@ pub fn is_readable(path string) bool {
return false
}
}
// get_long_path has no meaning for *nix, but has for windows, where `c:\folder\some~1` for example
// can be the equivalent of `c:\folder\some spa ces`. On *nix, it just returns a copy of the input path.
fn get_long_path(path string) !string {
return path
}

View File

@ -500,3 +500,9 @@ pub fn posix_set_permission_bit(path_s string, mode u32, enable bool) {
}
C.chmod(path, int(new_mode))
}
// get_long_path has no meaning for *nix, but has for windows, where `c:\folder\some~1` for example
// can be the equivalent of `c:\folder\some spa ces`. On *nix, it just returns a copy of the input path.
fn get_long_path(path string) !string {
return path
}

View File

@ -558,3 +558,24 @@ pub fn (mut c Command) read_line() string {
pub fn (mut c Command) close() ! {
panic('not implemented')
}
fn C.GetLongPathName(short_path &u16, long_path &u16, long_path_bufsize u32) u32
// get_long_path has no meaning for *nix, but has for windows, where `c:\folder\some~1` for example
// can be the equivalent of `c:\folder\some spa ces`. On *nix, it just returns a copy of the input path.
fn get_long_path(path string) !string {
if !path.contains('~') {
return path
}
input_short_path := path.to_wide()
defer {
unsafe { free(input_short_path) }
}
long_path_buf := [4096]u16{}
res := C.GetLongPathName(input_short_path, &long_path_buf[0], sizeof(long_path_buf))
if res == 0 {
return error(get_error_msg(int(C.GetLastError())))
}
long_path := unsafe { string_from_wide(&long_path_buf[0]) }
return long_path
}

View File

@ -115,7 +115,7 @@ fn signal_from_str(str JS.String) Signal {
// - Browser: Will use `window.addEventListener` for handling signal
//
// TODO: Add signal events implementation for browser backend
pub fn signal_opt(signum Signal, handler SignalHandler) ?SignalHandler {
pub fn signal_opt(signum Signal, handler SignalHandler) !SignalHandler {
signame := signal_str(signum)
_ := signame
$if js_node {