From fe65cde03b76b2ef3ca8620db581e2a91f53e81b Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 12 Jul 2021 13:23:25 +0200 Subject: [PATCH] tools: use os.symlink instead of system('ln -s') in `v symlink` (#10769) --- cmd/tools/vsymlink.v | 7 +++---- vlib/os/os_test.v | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/tools/vsymlink.v b/cmd/tools/vsymlink.v index cd6bb72a40..c5d7d8ab41 100644 --- a/cmd/tools/vsymlink.v +++ b/cmd/tools/vsymlink.v @@ -31,11 +31,10 @@ fn setup_symlink_unix(vexe string) { } link_path = link_dir + '/v' } - ret := os.execute('ln -sf "$vexe" "$link_path"') - if ret.exit_code == 0 { - println('Symlink "$link_path" has been created') - } else { + os.rm(link_path) or {} + os.symlink(vexe, link_path) or { eprintln('Failed to create symlink "$link_path". Try again with sudo.') + exit(1) } } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index ce670897a4..0c2c78824c 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -111,7 +111,7 @@ fn test_is_file() { assert true } $else { dsymlink := os.join_path(work_dir, 'dir_symlink') - os.system('ln -s $work_dir $dsymlink') + os.symlink(work_dir, dsymlink) or { panic(err) } assert os.is_file(dsymlink) == false } // Test file symlinks @@ -119,7 +119,7 @@ fn test_is_file() { assert true } $else { fsymlink := os.join_path(work_dir, 'file_symlink') - os.system('ln -s $tfile $fsymlink') + os.symlink(tfile, fsymlink) or { panic(err) } assert os.is_file(fsymlink) } }