mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: change all '$expr' to '${expr}' (#16428)
This commit is contained in:
@@ -16,7 +16,7 @@ fn test_tmpdir() {
|
||||
fn test_ensure_folder_is_writable() {
|
||||
tmp := os.temp_dir()
|
||||
os.ensure_folder_is_writable(tmp) or {
|
||||
eprintln('err: $err')
|
||||
eprintln('err: ${err}')
|
||||
assert false
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ fn test_expand_tilde_to_home() {
|
||||
fn test_config_dir() {
|
||||
cdir := os.config_dir()!
|
||||
assert cdir.len > 0
|
||||
adir := '$cdir/test-v-config'
|
||||
adir := '${cdir}/test-v-config'
|
||||
os.mkdir_all(adir)!
|
||||
os.rmdir(adir)!
|
||||
assert os.is_dir(cdir)
|
||||
|
@@ -45,7 +45,7 @@ pub fn getenv_opt(key string) ?string {
|
||||
// os.setenv sets the value of an environment variable with `name` to `value`.
|
||||
pub fn setenv(name string, value string, overwrite bool) int {
|
||||
$if windows {
|
||||
format := '$name=$value'
|
||||
format := '${name}=${value}'
|
||||
if overwrite {
|
||||
unsafe {
|
||||
return C._putenv(&char(format.str))
|
||||
@@ -68,7 +68,7 @@ pub fn setenv(name string, value string, overwrite bool) int {
|
||||
// os.unsetenv clears an environment variable with `name`.
|
||||
pub fn unsetenv(name string) int {
|
||||
$if windows {
|
||||
format := '$name='
|
||||
format := '${name}='
|
||||
return C._putenv(&char(format.str))
|
||||
} $else {
|
||||
return C.unsetenv(&char(name.str))
|
||||
|
@@ -43,12 +43,12 @@ fn test_environ() {
|
||||
|
||||
fn test_setenv_var_not_exists() {
|
||||
key := time.new_time(time.now()).unix
|
||||
os.setenv('foo$key', 'bar', false)
|
||||
assert os.getenv('foo$key') == 'bar'
|
||||
os.setenv('foo${key}', 'bar', false)
|
||||
assert os.getenv('foo${key}') == 'bar'
|
||||
}
|
||||
|
||||
fn test_getenv_empty_var() {
|
||||
key := time.new_time(time.now()).unix
|
||||
os.setenv('empty$key', '""', false)
|
||||
assert os.getenv('empty$key') == '""'
|
||||
os.setenv('empty${key}', '""', false)
|
||||
assert os.getenv('empty${key}') == '""'
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ pub fn open_file(path string, mode string, options ...int) !File {
|
||||
fdopen_mode := mode.replace('b', '')
|
||||
cfile := C.fdopen(fd, &char(fdopen_mode.str))
|
||||
if isnil(cfile) {
|
||||
return error('Failed to open or create file "$path"')
|
||||
return error('Failed to open or create file "${path}"')
|
||||
}
|
||||
if seek_to_end {
|
||||
// ensure appending will work, even on bsd/macos systems:
|
||||
@@ -227,7 +227,7 @@ pub fn (mut f File) reopen(path string, mode string) ! {
|
||||
cfile = C.freopen(&char(p.str), &char(mode.str), f.cfile)
|
||||
}
|
||||
if isnil(cfile) {
|
||||
return error('Failed to reopen file "$path"')
|
||||
return error('Failed to reopen file "${path}"')
|
||||
}
|
||||
f.cfile = cfile
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ pub fn (mut l FileLock) acquire() ! {
|
||||
}
|
||||
fd := open_lockfile(l.name)
|
||||
if fd == -1 {
|
||||
return error_with_code('cannot create lock file $l.name', -1)
|
||||
return error_with_code('cannot create lock file ${l.name}', -1)
|
||||
}
|
||||
if C.flock(fd, C.LOCK_EX) == -1 {
|
||||
C.close(fd)
|
||||
@@ -66,7 +66,7 @@ pub fn (mut l FileLock) try_acquire() bool {
|
||||
if l.fd != -1 {
|
||||
return true
|
||||
}
|
||||
fd := open_lockfile('$l.name')
|
||||
fd := open_lockfile('${l.name}')
|
||||
if fd != -1 {
|
||||
err := C.flock(fd, C.LOCK_EX | C.LOCK_NB)
|
||||
if err == -1 {
|
||||
|
@@ -21,7 +21,7 @@ pub fn (mut l FileLock) acquire() ! {
|
||||
}
|
||||
fd := open(l.name)
|
||||
if fd == -1 {
|
||||
return error_with_code('cannot create lock file $l.name', -1)
|
||||
return error_with_code('cannot create lock file ${l.name}', -1)
|
||||
}
|
||||
l.fd = fd
|
||||
}
|
||||
|
@@ -154,9 +154,9 @@ fn test_existing_path() {
|
||||
assert existing_path('.') or { '' } == '.'
|
||||
assert existing_path(wd) or { '' } == wd
|
||||
assert existing_path('\\') or { '' } == '\\'
|
||||
assert existing_path('$wd\\.\\\\does/not/exist\\.\\') or { '' } == '$wd\\.\\\\'
|
||||
assert existing_path('$wd\\\\/\\.\\.\\/.') or { '' } == '$wd\\\\/\\.\\.\\/.'
|
||||
assert existing_path('$wd\\././/\\/oh') or { '' } == '$wd\\././/\\/'
|
||||
assert existing_path('${wd}\\.\\\\does/not/exist\\.\\') or { '' } == '${wd}\\.\\\\'
|
||||
assert existing_path('${wd}\\\\/\\.\\.\\/.') or { '' } == '${wd}\\\\/\\.\\.\\/.'
|
||||
assert existing_path('${wd}\\././/\\/oh') or { '' } == '${wd}\\././/\\/'
|
||||
return
|
||||
}
|
||||
assert existing_path('') or { '' } == ''
|
||||
@@ -164,9 +164,9 @@ fn test_existing_path() {
|
||||
assert existing_path('.') or { '' } == '.'
|
||||
assert existing_path(wd) or { '' } == wd
|
||||
assert existing_path('/') or { '' } == '/'
|
||||
assert existing_path('$wd/does/.///not/exist///.//') or { '' } == '$wd/'
|
||||
assert existing_path('$wd//././/.//') or { '' } == '$wd//././/.//'
|
||||
assert existing_path('$wd//././/.//oh') or { '' } == '$wd//././/.//'
|
||||
assert existing_path('${wd}/does/.///not/exist///.//') or { '' } == '${wd}/'
|
||||
assert existing_path('${wd}//././/.//') or { '' } == '${wd}//././/.//'
|
||||
assert existing_path('${wd}//././/.//oh') or { '' } == '${wd}//././/.//'
|
||||
}
|
||||
|
||||
fn test_windows_volume() {
|
||||
|
@@ -41,7 +41,7 @@ fn test_find_abs_path_of_executable() {
|
||||
os.setenv('PATH', original_path, true)
|
||||
os.chdir(os.home_dir())! // change to a *completely* different folder, to avoid the original PATH containing `.`
|
||||
if x := os.find_abs_path_of_executable('myclang') {
|
||||
eprintln('> find_abs_path_of_executable should have failed, but instead it found: $x')
|
||||
eprintln('> find_abs_path_of_executable should have failed, but instead it found: ${x}')
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ pub fn default() string {
|
||||
'/Library/Fonts/Arial.ttf']
|
||||
for font in fonts {
|
||||
if os.is_file(font) {
|
||||
debug_font_println('Using font "$font"')
|
||||
debug_font_println('Using font "${font}"')
|
||||
return font
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ pub fn default() string {
|
||||
for location in font_locations {
|
||||
candidate_path := os.join_path(location, candidate_font)
|
||||
if os.is_file(candidate_path) && os.is_readable(candidate_path) {
|
||||
debug_font_println('Using font "$candidate_path"')
|
||||
debug_font_println('Using font "${candidate_path}"')
|
||||
return candidate_path
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ pub fn default() string {
|
||||
lines := fm.output.split('\n')
|
||||
for l in lines {
|
||||
if !l.contains('.ttc') {
|
||||
debug_font_println('Using font "$l"')
|
||||
debug_font_println('Using font "${l}"')
|
||||
return l
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ const (
|
||||
)
|
||||
|
||||
fn testsuite_begin() {
|
||||
eprintln('testsuite_begin, tfolder = $tfolder')
|
||||
eprintln('testsuite_begin, tfolder = ${tfolder}')
|
||||
os.rmdir_all(tfolder) or {}
|
||||
assert !os.is_dir(tfolder)
|
||||
os.mkdir_all(tfolder) or { panic(err) }
|
||||
|
@@ -8,7 +8,7 @@ fn make_pipe() !(int, int) {
|
||||
$if linux {
|
||||
pipefd := [2]int{}
|
||||
if C.pipe(&pipefd[0]) != 0 {
|
||||
return error('error $C.errno: ' + os.posix_get_error_msg(C.errno))
|
||||
return error('error ${C.errno}: ' + os.posix_get_error_msg(C.errno))
|
||||
}
|
||||
return pipefd[0], pipefd[1]
|
||||
}
|
||||
|
@@ -23,8 +23,8 @@ pub fn open_uri(uri string) ! {
|
||||
if vopen_uri_cmd == '' {
|
||||
return error('unsupported platform')
|
||||
}
|
||||
result := execute('$vopen_uri_cmd "$uri"')
|
||||
result := execute('${vopen_uri_cmd} "${uri}"')
|
||||
if result.exit_code != 0 {
|
||||
return error('unable to open url: $result.output')
|
||||
return error('unable to open url: ${result.output}')
|
||||
}
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@ type ShellExecuteWin = fn (voidptr, &u16, &u16, &u16, &u16, int)
|
||||
pub fn open_uri(uri string) ! {
|
||||
mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
|
||||
if vopen_uri_cmd != '' {
|
||||
result := execute('$vopen_uri_cmd "$uri"')
|
||||
result := execute('${vopen_uri_cmd} "${uri}"')
|
||||
if result.exit_code != 0 {
|
||||
return error('unable to open url: $result.output')
|
||||
return error('unable to open url: ${result.output}')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ fn find_cfile_size(fp &C.FILE) !int {
|
||||
len := int(raw_fsize)
|
||||
// For files > 2GB, C.ftell can return values that, when cast to `int`, can result in values below 0.
|
||||
if i64(len) < raw_fsize {
|
||||
return error('int($raw_fsize) cast results in $len')
|
||||
return error('int(${raw_fsize}) cast results in ${len}')
|
||||
}
|
||||
C.rewind(fp)
|
||||
return len
|
||||
@@ -222,12 +222,12 @@ pub fn mv(src string, dst string) ! {
|
||||
w_dst := rdst.replace('/', '\\')
|
||||
ret := C._wrename(w_src.to_wide(), w_dst.to_wide())
|
||||
if ret != 0 {
|
||||
return error_with_code('failed to rename $src to $dst', int(ret))
|
||||
return error_with_code('failed to rename ${src} to ${dst}', int(ret))
|
||||
}
|
||||
} $else {
|
||||
ret := C.rename(&char(src.str), &char(rdst.str))
|
||||
if ret != 0 {
|
||||
return error_with_code('failed to rename $src to $dst', ret)
|
||||
return error_with_code('failed to rename ${src} to ${dst}', ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,17 +239,17 @@ pub fn cp(src string, dst string) ! {
|
||||
w_dst := dst.replace('/', '\\')
|
||||
if C.CopyFile(w_src.to_wide(), w_dst.to_wide(), false) == 0 {
|
||||
result := C.GetLastError()
|
||||
return error_with_code('failed to copy $src to $dst', int(result))
|
||||
return error_with_code('failed to copy ${src} to ${dst}', int(result))
|
||||
}
|
||||
} $else {
|
||||
fp_from := C.open(&char(src.str), C.O_RDONLY, 0)
|
||||
if fp_from < 0 { // Check if file opened
|
||||
return error_with_code('cp: failed to open $src', int(fp_from))
|
||||
return error_with_code('cp: failed to open ${src}', int(fp_from))
|
||||
}
|
||||
fp_to := C.open(&char(dst.str), C.O_WRONLY | C.O_CREAT | C.O_TRUNC, C.S_IWUSR | C.S_IRUSR)
|
||||
if fp_to < 0 { // Check if file opened (permissions problems ...)
|
||||
C.close(fp_from)
|
||||
return error_with_code('cp (permission): failed to write to $dst (fp_to: $fp_to)',
|
||||
return error_with_code('cp (permission): failed to write to ${dst} (fp_to: ${fp_to})',
|
||||
int(fp_to))
|
||||
}
|
||||
// TODO use defer{} to close files in case of error or return.
|
||||
@@ -264,7 +264,7 @@ pub fn cp(src string, dst string) ! {
|
||||
if C.write(fp_to, &buf[0], count) < 0 {
|
||||
C.close(fp_to)
|
||||
C.close(fp_from)
|
||||
return error_with_code('cp: failed to write to $dst', int(-1))
|
||||
return error_with_code('cp: failed to write to ${dst}', int(-1))
|
||||
}
|
||||
}
|
||||
from_attr := C.stat{}
|
||||
@@ -274,7 +274,7 @@ pub fn cp(src string, dst string) ! {
|
||||
if C.chmod(&char(dst.str), from_attr.st_mode) < 0 {
|
||||
C.close(fp_to)
|
||||
C.close(fp_from)
|
||||
return error_with_code('failed to set permissions for $dst', int(-1))
|
||||
return error_with_code('failed to set permissions for ${dst}', int(-1))
|
||||
}
|
||||
C.close(fp_to)
|
||||
C.close(fp_from)
|
||||
@@ -295,7 +295,7 @@ pub fn vfopen(path string, mode string) !&C.FILE {
|
||||
fp = C.fopen(&char(path.str), &char(mode.str))
|
||||
}
|
||||
if isnil(fp) {
|
||||
return error('failed to open file "$path"')
|
||||
return error('failed to open file "${path}"')
|
||||
} else {
|
||||
return fp
|
||||
}
|
||||
@@ -373,7 +373,7 @@ pub fn system(cmd string) int {
|
||||
mut ret := 0
|
||||
$if windows {
|
||||
// overcome bug in system & _wsystem (cmd) when first char is quote `"`
|
||||
wcmd := if cmd.len > 1 && cmd[0] == `"` && cmd[1] != `"` { '"$cmd"' } else { cmd }
|
||||
wcmd := if cmd.len > 1 && cmd[0] == `"` && cmd[1] != `"` { '"${cmd}"' } else { cmd }
|
||||
unsafe {
|
||||
ret = C._wsystem(wcmd.to_wide())
|
||||
}
|
||||
@@ -487,7 +487,7 @@ pub fn rm(path string) ! {
|
||||
rc = C.remove(&char(path.str))
|
||||
}
|
||||
if rc == -1 {
|
||||
return error('Failed to remove "$path": ' + posix_get_error_msg(C.errno))
|
||||
return error('Failed to remove "${path}": ' + posix_get_error_msg(C.errno))
|
||||
}
|
||||
// C.unlink(path.cstr())
|
||||
}
|
||||
@@ -498,7 +498,7 @@ pub fn rmdir(path string) ! {
|
||||
rc := C.RemoveDirectory(path.to_wide())
|
||||
if !rc {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya - 0 == false, is failure
|
||||
return error('Failed to remove "$path": ' + posix_get_error_msg(C.errno))
|
||||
return error('Failed to remove "${path}": ' + posix_get_error_msg(C.errno))
|
||||
}
|
||||
} $else {
|
||||
rc := C.rmdir(&char(path.str))
|
||||
@@ -512,7 +512,7 @@ pub fn rmdir(path string) ! {
|
||||
fn print_c_errno() {
|
||||
e := C.errno
|
||||
se := unsafe { tos_clone(&u8(C.strerror(e))) }
|
||||
println('errno=$e err=$se')
|
||||
println('errno=${e} err=${se}')
|
||||
}
|
||||
|
||||
// get_raw_line returns a one-line string from stdin along with '\n' if there is any.
|
||||
@@ -612,7 +612,7 @@ pub fn read_file_array<T>(path string) []T {
|
||||
// On some systems C.ftell can return values in the 64-bit range
|
||||
// that, when cast to `int`, can result in values below 0.
|
||||
if i64(allocate) < fsize {
|
||||
panic('$fsize cast to int results in ${int(fsize)})')
|
||||
panic('${fsize} cast to int results in ${int(fsize)})')
|
||||
}
|
||||
buf := unsafe {
|
||||
malloc_noscan(allocate)
|
||||
@@ -672,7 +672,7 @@ pub fn executable() string {
|
||||
pid := C.getpid()
|
||||
ret := proc_pidpath(pid, &result[0], max_path_len)
|
||||
if ret <= 0 {
|
||||
eprintln('os.executable() failed at calling proc_pidpath with pid: $pid . proc_pidpath returned $ret ')
|
||||
eprintln('os.executable() failed at calling proc_pidpath with pid: ${pid} . proc_pidpath returned ${ret} ')
|
||||
return executable_fallback()
|
||||
}
|
||||
res := unsafe { tos_clone(&result[0]) }
|
||||
@@ -985,7 +985,7 @@ pub fn open_append(path string) !File {
|
||||
}
|
||||
}
|
||||
if isnil(file.cfile) {
|
||||
return error('failed to create(append) file "$path"')
|
||||
return error('failed to create(append) file "${path}"')
|
||||
}
|
||||
file.is_opened = true
|
||||
return file
|
||||
|
22
vlib/os/os.v
22
vlib/os/os.v
@@ -396,7 +396,7 @@ pub fn user_names() ![]string {
|
||||
$if windows {
|
||||
result := execute('wmic useraccount get name')
|
||||
if result.exit_code != 0 {
|
||||
return error('Failed to get user names. Exited with code $result.exit_code: $result.output')
|
||||
return error('Failed to get user names. Exited with code ${result.exit_code}: ${result.output}')
|
||||
}
|
||||
mut users := result.output.split_into_lines()
|
||||
// windows command prints an empty line at the end of output
|
||||
@@ -662,7 +662,7 @@ pub fn mkdir_all(opath string, params MkdirParams) ! {
|
||||
if exists(p) && is_dir(p) {
|
||||
continue
|
||||
}
|
||||
mkdir(p, params) or { return error('folder: $p, error: $err') }
|
||||
mkdir(p, params) or { return error('folder: ${p}, error: ${err}') }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,7 +727,7 @@ pub fn vtmp_dir() string {
|
||||
return vtmp
|
||||
}
|
||||
uid := getuid()
|
||||
vtmp = join_path_single(temp_dir(), 'v_$uid')
|
||||
vtmp = join_path_single(temp_dir(), 'v_${uid}')
|
||||
if !exists(vtmp) || !is_dir(vtmp) {
|
||||
// create a new directory, that is private to the user:
|
||||
mkdir_all(vtmp, mode: 0o700) or { panic(err) }
|
||||
@@ -817,8 +817,8 @@ pub mut:
|
||||
pub fn execute_or_panic(cmd string) Result {
|
||||
res := execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
eprintln('failed cmd: $cmd')
|
||||
eprintln('failed code: $res.exit_code')
|
||||
eprintln('failed cmd: ${cmd}')
|
||||
eprintln('failed code: ${res.exit_code}')
|
||||
panic(res.output)
|
||||
}
|
||||
return res
|
||||
@@ -827,8 +827,8 @@ pub fn execute_or_panic(cmd string) Result {
|
||||
pub fn execute_or_exit(cmd string) Result {
|
||||
res := execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
eprintln('failed cmd: $cmd')
|
||||
eprintln('failed code: $res.exit_code')
|
||||
eprintln('failed cmd: ${cmd}')
|
||||
eprintln('failed code: ${res.exit_code}')
|
||||
eprintln(res.output)
|
||||
exit(1)
|
||||
}
|
||||
@@ -838,9 +838,13 @@ pub fn execute_or_exit(cmd string) Result {
|
||||
// quoted path - return a quoted version of the path, depending on the platform.
|
||||
pub fn quoted_path(path string) string {
|
||||
$if windows {
|
||||
return if path.ends_with(path_separator) { '"${path + path_separator}"' } else { '"$path"' }
|
||||
return if path.ends_with(path_separator) {
|
||||
'"${path + path_separator}"'
|
||||
} else {
|
||||
'"${path}"'
|
||||
}
|
||||
} $else {
|
||||
return "'$path'"
|
||||
return "'${path}'"
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ fn C.AAssetManager_open(&C.AAssetManager, &char, int) &C.AAsset
|
||||
pub fn (am &AssetManager) open(filename string, mode AssetMode) !&Asset {
|
||||
asset := C.AAssetManager_open(am, filename.str, int(mode))
|
||||
if isnil(asset) {
|
||||
return error('file `$filename` not found')
|
||||
return error('file `${filename}` not found')
|
||||
}
|
||||
return asset
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ pub fn exists(path string) bool {
|
||||
|
||||
pub fn ls(path string) ![]string {
|
||||
if !is_dir(path) {
|
||||
return error('ls(): cannot open dir $dir')
|
||||
return error('ls(): cannot open dir ${dir}')
|
||||
}
|
||||
|
||||
result := []string{}
|
||||
|
@@ -87,8 +87,8 @@ fn glob_match(dir string, pattern string, next_pattern string, mut matches []str
|
||||
mode = GlobMatch.any
|
||||
if next_pattern != pattern && next_pattern != '' {
|
||||
for file in files {
|
||||
if is_dir('$dir/$file') {
|
||||
subdirs << '$dir/$file'
|
||||
if is_dir('${dir}/${file}') {
|
||||
subdirs << '${dir}/${file}'
|
||||
}
|
||||
}
|
||||
return subdirs
|
||||
@@ -115,7 +115,7 @@ fn glob_match(dir string, pattern string, next_pattern string, mut matches []str
|
||||
pathwalk := file.split(os.path_separator)
|
||||
pathwalk[pathwalk.len - 1]
|
||||
} else {
|
||||
fpath = if dir == '.' { file } else { '$dir/$file' }
|
||||
fpath = if dir == '.' { file } else { '${dir}/${file}' }
|
||||
file
|
||||
}
|
||||
if f in ['.', '..'] || f == '' {
|
||||
@@ -146,7 +146,7 @@ fn glob_match(dir string, pattern string, next_pattern string, mut matches []str
|
||||
if is_dir(fpath) {
|
||||
subdirs << fpath
|
||||
if next_pattern == pattern && next_pattern != '' {
|
||||
matches << '$fpath$os.path_separator'
|
||||
matches << '${fpath}${os.path_separator}'
|
||||
}
|
||||
} else {
|
||||
matches << fpath
|
||||
@@ -166,14 +166,14 @@ fn native_glob_pattern(pattern string, mut matches []string) ! {
|
||||
if step == '' {
|
||||
continue
|
||||
}
|
||||
if is_dir('$cwd$os.path_separator$step') {
|
||||
if is_dir('${cwd}${os.path_separator}${step}') {
|
||||
dd := if cwd == '/' {
|
||||
step
|
||||
} else {
|
||||
if cwd == '.' || cwd == '' {
|
||||
step
|
||||
} else {
|
||||
if step == '.' || step == '/' { cwd } else { '$cwd/$step' }
|
||||
if step == '.' || step == '/' { cwd } else { '${cwd}/${step}' }
|
||||
}
|
||||
}
|
||||
if i + 1 != steps.len {
|
||||
@@ -190,7 +190,7 @@ fn native_glob_pattern(pattern string, mut matches []string) ! {
|
||||
if cwd == '.' || cwd == '' {
|
||||
sd
|
||||
} else {
|
||||
if sd == '.' || sd == '/' { cwd } else { '$cwd/$sd' }
|
||||
if sd == '.' || sd == '/' { cwd } else { '${cwd}/${sd}' }
|
||||
}
|
||||
}
|
||||
subs << glob_match(d.replace('//', '/'), step, step2, mut matches)
|
||||
@@ -259,7 +259,7 @@ pub fn ls(path string) ![]string {
|
||||
mut res := []string{cap: 50}
|
||||
dir := unsafe { C.opendir(&char(path.str)) }
|
||||
if isnil(dir) {
|
||||
return error('ls() couldnt open dir "$path"')
|
||||
return error('ls() couldnt open dir "${path}"')
|
||||
}
|
||||
mut ent := &C.dirent(0)
|
||||
// mut ent := &C.dirent{!}
|
||||
@@ -299,7 +299,7 @@ pub fn execute(cmd string) Result {
|
||||
// if cmd.contains(';') || cmd.contains('&&') || cmd.contains('||') || cmd.contains('\n') {
|
||||
// return Result{ exit_code: -1, output: ';, &&, || and \\n are not allowed in shell commands' }
|
||||
// }
|
||||
pcmd := if cmd.contains('2>') { cmd.clone() } else { '$cmd 2>&1' }
|
||||
pcmd := if cmd.contains('2>') { cmd.clone() } else { '${cmd} 2>&1' }
|
||||
defer {
|
||||
unsafe { pcmd.free() }
|
||||
}
|
||||
@@ -307,7 +307,7 @@ pub fn execute(cmd string) Result {
|
||||
if isnil(f) {
|
||||
return Result{
|
||||
exit_code: -1
|
||||
output: 'exec("$cmd") failed'
|
||||
output: 'exec("${cmd}") failed'
|
||||
}
|
||||
}
|
||||
fd := fileno(f)
|
||||
@@ -351,7 +351,7 @@ pub fn (mut c Command) start() ! {
|
||||
}
|
||||
c.f = vpopen(pcmd)
|
||||
if isnil(c.f) {
|
||||
return error('exec("$c.path") failed')
|
||||
return error('exec("${c.path}") failed')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,10 +437,10 @@ fn C.mkstemp(stemplate &u8) int
|
||||
[manualfree]
|
||||
pub fn ensure_folder_is_writable(folder string) ! {
|
||||
if !exists(folder) {
|
||||
return error_with_code('`$folder` does not exist', 1)
|
||||
return error_with_code('`${folder}` does not exist', 1)
|
||||
}
|
||||
if !is_dir(folder) {
|
||||
return error_with_code('`$folder` is not a folder', 2)
|
||||
return error_with_code('`${folder}` is not a folder', 2)
|
||||
}
|
||||
tmp_perm_check := join_path_single(folder, 'XXXXXX')
|
||||
defer {
|
||||
@@ -449,7 +449,7 @@ pub fn ensure_folder_is_writable(folder string) ! {
|
||||
unsafe {
|
||||
x := C.mkstemp(&char(tmp_perm_check.str))
|
||||
if -1 == x {
|
||||
return error_with_code('folder `$folder` is not writable', 3)
|
||||
return error_with_code('folder `${folder}` is not writable', 3)
|
||||
}
|
||||
C.close(x)
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ const (
|
||||
const args_at_start = os.args.clone()
|
||||
|
||||
fn testsuite_begin() {
|
||||
eprintln('testsuite_begin, tfolder = $tfolder')
|
||||
eprintln('testsuite_begin, tfolder = ${tfolder}')
|
||||
os.rmdir_all(tfolder) or {}
|
||||
assert !os.is_dir(tfolder)
|
||||
os.mkdir_all(tfolder) or { panic(err) }
|
||||
@@ -42,7 +42,7 @@ fn test_open_file() {
|
||||
file.write_string(hello) or { panic(err) }
|
||||
file.close()
|
||||
assert u64(hello.len) == os.file_size(filename)
|
||||
read_hello := os.read_file(filename) or { panic('error reading file $filename') }
|
||||
read_hello := os.read_file(filename) or { panic('error reading file ${filename}') }
|
||||
assert hello == read_hello
|
||||
os.rm(filename) or { panic(err) }
|
||||
}
|
||||
@@ -82,7 +82,7 @@ fn test_open_file_binary() {
|
||||
unsafe { file.write_ptr(bytes.data, bytes.len) }
|
||||
file.close()
|
||||
assert u64(hello.len) == os.file_size(filename)
|
||||
read_hello := os.read_bytes(filename) or { panic('error reading file $filename') }
|
||||
read_hello := os.read_bytes(filename) or { panic('error reading file ${filename}') }
|
||||
assert bytes == read_hello
|
||||
os.rm(filename) or { panic(err) }
|
||||
}
|
||||
@@ -162,7 +162,7 @@ fn test_write_and_read_string_to_file() {
|
||||
hello := 'hello world!'
|
||||
os.write_file(filename, hello) or { panic(err) }
|
||||
assert u64(hello.len) == os.file_size(filename)
|
||||
read_hello := os.read_file(filename) or { panic('error reading file $filename') }
|
||||
read_hello := os.read_file(filename) or { panic('error reading file ${filename}') }
|
||||
assert hello == read_hello
|
||||
os.rm(filename) or { panic(err) }
|
||||
}
|
||||
@@ -173,7 +173,7 @@ fn test_write_and_read_bytes() {
|
||||
file_name := './byte_reader_writer.tst'
|
||||
payload := [u8(`I`), `D`, `D`, `Q`, `D`]
|
||||
mut file_write := os.create(os.real_path(file_name)) or {
|
||||
eprintln('failed to create file $file_name')
|
||||
eprintln('failed to create file ${file_name}')
|
||||
return
|
||||
}
|
||||
// We use the standard write_bytes function to write the payload and
|
||||
@@ -182,7 +182,7 @@ fn test_write_and_read_bytes() {
|
||||
file_write.close()
|
||||
assert u64(payload.len) == os.file_size(file_name)
|
||||
mut file_read := os.open(os.real_path(file_name)) or {
|
||||
eprintln('failed to open file $file_name')
|
||||
eprintln('failed to open file ${file_name}')
|
||||
return
|
||||
}
|
||||
// We only need to test read_bytes because this function calls
|
||||
@@ -323,7 +323,7 @@ fn test_cp() {
|
||||
old_file_name := 'cp_example.txt'
|
||||
new_file_name := 'cp_new_example.txt'
|
||||
os.write_file(old_file_name, 'Test data 1 2 3, V is awesome #$%^[]!~⭐') or { panic(err) }
|
||||
os.cp(old_file_name, new_file_name) or { panic('$err') }
|
||||
os.cp(old_file_name, new_file_name) or { panic('${err}') }
|
||||
old_file := os.read_file(old_file_name) or { panic(err) }
|
||||
new_file := os.read_file(new_file_name) or { panic(err) }
|
||||
assert old_file == new_file
|
||||
|
@@ -167,11 +167,11 @@ pub fn ls(path string) ![]string {
|
||||
// }
|
||||
// C.FindClose(h_find_dir)
|
||||
if !is_dir(path) {
|
||||
return error('ls() couldnt open dir "$path": directory does not exist')
|
||||
return error('ls() couldnt open dir "${path}": directory does not exist')
|
||||
}
|
||||
// NOTE: Should eventually have path struct & os dependant path seperator (eg os.PATH_SEPERATOR)
|
||||
// we need to add files to path eg. c:\windows\*.dll or :\windows\*
|
||||
path_files := '$path\\*'
|
||||
path_files := '${path}\\*'
|
||||
// NOTE:TODO: once we have a way to convert utf16 wide character to utf8
|
||||
// we should use FindFirstFileW and FindNextFileW
|
||||
h_find_files := C.FindFirstFile(path_files.to_wide(), voidptr(&find_file_data))
|
||||
@@ -196,7 +196,7 @@ pub fn mkdir(path string, params MkdirParams) ! {
|
||||
}
|
||||
apath := real_path(path)
|
||||
if !C.CreateDirectory(apath.to_wide(), 0) {
|
||||
return error('mkdir failed for "$apath", because CreateDirectory returned: ' +
|
||||
return error('mkdir failed for "${apath}", because CreateDirectory returned: ' +
|
||||
get_error_msg(int(C.GetLastError())))
|
||||
}
|
||||
}
|
||||
@@ -311,7 +311,7 @@ pub fn raw_execute(cmd string) Result {
|
||||
error_msg := get_error_msg(error_num)
|
||||
return Result{
|
||||
exit_code: error_num
|
||||
output: 'exec failed (CreatePipe): $error_msg'
|
||||
output: 'exec failed (CreatePipe): ${error_msg}'
|
||||
}
|
||||
}
|
||||
set_handle_info_ok := C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT,
|
||||
@@ -321,7 +321,7 @@ pub fn raw_execute(cmd string) Result {
|
||||
error_msg := get_error_msg(error_num)
|
||||
return Result{
|
||||
exit_code: error_num
|
||||
output: 'exec failed (SetHandleInformation): $error_msg'
|
||||
output: 'exec failed (SetHandleInformation): ${error_msg}'
|
||||
}
|
||||
}
|
||||
proc_info := ProcessInformation{}
|
||||
@@ -345,7 +345,7 @@ pub fn raw_execute(cmd string) Result {
|
||||
error_msg := get_error_msg(error_num)
|
||||
return Result{
|
||||
exit_code: error_num
|
||||
output: 'exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd'
|
||||
output: 'exec failed (CreateProcess) with code ${error_num}: ${error_msg} cmd: ${cmd}'
|
||||
}
|
||||
}
|
||||
C.CloseHandle(child_stdin)
|
||||
@@ -496,7 +496,7 @@ pub fn loginname() string {
|
||||
// by creating an empty file in it, then deleting it.
|
||||
pub fn ensure_folder_is_writable(folder string) ! {
|
||||
if !exists(folder) {
|
||||
return error_with_code('`$folder` does not exist', 1)
|
||||
return error_with_code('`${folder}` does not exist', 1)
|
||||
}
|
||||
if !is_dir(folder) {
|
||||
return error_with_code('`folder` is not a folder', 2)
|
||||
@@ -504,7 +504,7 @@ pub fn ensure_folder_is_writable(folder string) ! {
|
||||
tmp_folder_name := 'tmp_perm_check_pid_' + getpid().str()
|
||||
tmp_perm_check := join_path_single(folder, tmp_folder_name)
|
||||
write_file(tmp_perm_check, 'test') or {
|
||||
return error_with_code('cannot write to folder "$folder": $err', 3)
|
||||
return error_with_code('cannot write to folder "${folder}": ${err}', 3)
|
||||
}
|
||||
rm(tmp_perm_check)!
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ fn (mut p Process) _spawn() int {
|
||||
p.env = []string{}
|
||||
current_environment := environ()
|
||||
for k, v in current_environment {
|
||||
p.env << '$k=$v'
|
||||
p.env << '${k}=${v}'
|
||||
}
|
||||
}
|
||||
mut pid := 0
|
||||
@@ -177,7 +177,7 @@ pub fn (mut p Process) stderr_read() string {
|
||||
// _check_redirection_call - should be called just by stdxxx methods
|
||||
fn (mut p Process) _check_redirection_call(fn_name string) {
|
||||
if !p.use_stdio_ctl {
|
||||
panic('Call p.set_redirect_stdio() before calling p.$fn_name')
|
||||
panic('Call p.set_redirect_stdio() before calling p.${fn_name}')
|
||||
}
|
||||
if p.status == .not_started {
|
||||
panic('Call p.${fn_name}() after you have called p.run()')
|
||||
|
@@ -114,7 +114,7 @@ pub fn (mut p Process) stdout_slurp() string {
|
||||
// _check_redirection_call - should be called just by stdxxx methods
|
||||
fn (mut p Process) check_redirection_call(fn_name string) {
|
||||
if !p.use_stdio_ctl {
|
||||
panic('Call p.set_redirect_stdio() before calling p.$fn_name')
|
||||
panic('Call p.set_redirect_stdio() before calling p.${fn_name}')
|
||||
}
|
||||
if p.status == .not_started {
|
||||
panic('Call p.${fn_name}() after you have called p.run()')
|
||||
|
@@ -64,7 +64,7 @@ pub fn (mut p Process) set_environment(envs map[string]string) {
|
||||
p.env_is_custom = true
|
||||
p.env = []string{}
|
||||
for k, v in envs {
|
||||
p.env << '$k=$v'
|
||||
p.env << '${k}=${v}'
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ fn testsuite_end() {
|
||||
|
||||
fn test_getpid() {
|
||||
pid := os.getpid()
|
||||
eprintln('current pid: $pid')
|
||||
eprintln('current pid: ${pid}')
|
||||
assert pid != 0
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ fn test_run() {
|
||||
break
|
||||
}
|
||||
$if trace_process_output ? {
|
||||
os.system('ps -opid= -oppid= -ouser= -onice= -of= -ovsz= -orss= -otime= -oargs= -p $p.pid')
|
||||
os.system('ps -opid= -oppid= -ouser= -onice= -of= -ovsz= -orss= -otime= -oargs= -p ${p.pid}')
|
||||
}
|
||||
time.sleep(50 * time.millisecond)
|
||||
i++
|
||||
@@ -58,7 +58,7 @@ fn test_run() {
|
||||
assert p.code == 0
|
||||
assert p.status == .exited
|
||||
//
|
||||
eprintln('polling iterations: $i')
|
||||
eprintln('polling iterations: ${i}')
|
||||
assert i < 50
|
||||
p.close()
|
||||
}
|
||||
@@ -86,8 +86,8 @@ fn test_slurping_output() {
|
||||
p.close()
|
||||
$if trace_process_output ? {
|
||||
eprintln('---------------------------')
|
||||
eprintln('p output: "$output"')
|
||||
eprintln('p errors: "$errors"')
|
||||
eprintln('p output: "${output}"')
|
||||
eprintln('p errors: "${errors}"')
|
||||
eprintln('---------------------------')
|
||||
}
|
||||
// dump(output)
|
||||
|
@@ -25,7 +25,7 @@ fn failed_cfn_report_error(ok bool, label string) {
|
||||
}
|
||||
error_num := int(C.GetLastError())
|
||||
error_msg := get_error_msg(error_num)
|
||||
eprintln('failed $label: $error_msg')
|
||||
eprintln('failed ${label}: ${error_msg}')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ fn (mut p Process) win_spawn_process() int {
|
||||
start_info.h_std_error = wdata.child_stderr_write
|
||||
start_info.dw_flags = u32(C.STARTF_USESTDHANDLES)
|
||||
}
|
||||
cmd := '$p.filename ' + p.args.join(' ')
|
||||
cmd := '${p.filename} ' + p.args.join(' ')
|
||||
C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&wdata.command_line[0]), 32768)
|
||||
|
||||
mut creation_flags := int(C.NORMAL_PRIORITY_CLASS)
|
||||
@@ -171,7 +171,7 @@ fn (mut p Process) win_is_alive() bool {
|
||||
///////////////
|
||||
|
||||
fn (mut p Process) win_write_string(idx int, s string) {
|
||||
panic('Process.write_string $idx is not implemented yet')
|
||||
panic('Process.write_string ${idx} is not implemented yet')
|
||||
}
|
||||
|
||||
fn (mut p Process) win_read_string(idx int, maxbytes int) (string, int) {
|
||||
|
@@ -2,7 +2,7 @@ module os
|
||||
|
||||
fn signal_str(signal Signal) string {
|
||||
mut result := signal.str().to_upper()
|
||||
result = 'SIG$result'
|
||||
result = 'SIG${result}'
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ fn signal_from_str(str JS.String) Signal {
|
||||
Signal.sys
|
||||
}
|
||||
else {
|
||||
panic('unknown signal: $s')
|
||||
panic('unknown signal: ${s}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user