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

os: replace dir_exists with is_dir; file_exists() => exists()

This commit is contained in:
Alexander Medvednikov
2019-12-04 23:03:12 +03:00
parent fb237b9e53
commit a57e29dfc5
28 changed files with 116 additions and 98 deletions

View File

@ -9,7 +9,7 @@ fn main() {
exe := os.executable()
dir := os.dir(exe)
vdir := os.dir(os.dir(dir))
if !os.file_exists('$vdir/v') && !os.dir_exists('$vdir/vlib') {
if !os.exists('$vdir/v') && !os.is_dir('$vdir/vlib') {
println('fast.html generator needs to be located in `v/tools/fast/`')
}
println('fast.html generator\n')
@ -18,7 +18,7 @@ fn main() {
exec('git pull --rebase')
mut commit_hash := exec('git rev-parse HEAD')
commit_hash = commit_hash[..7]
if !os.file_exists('table.html') {
if !os.exists('table.html') {
os.create('table.html') or { panic(err) }
}
mut table := os.read_file('table.html') or { panic(err) }

View File

@ -114,18 +114,18 @@ fn main() {
fp.version(app_version)
fp.description(app_description)
fp.skip_executable()
show_help:=fp.bool('help', false, 'Show this help screen\n')
flag_options := parse_flags(mut fp)
if( show_help ){ println( fp.usage() ) exit(0) }
fp.finalize() or {
eprintln(err)
println(fp.usage())
return
}
// webhook server mode
if flag_options.serve {
app := WebhookServer{ gen_vc: new_gen_vc(flag_options) }
@ -198,11 +198,11 @@ fn (gen_vc mut GenVC) generate() {
gen_vc.gen_error = false
// check if gen_vc dir exists
if !os.dir_exists(gen_vc.options.work_dir) {
if !os.is_dir(gen_vc.options.work_dir) {
// try create
os.mkdir(gen_vc.options.work_dir) or { panic(err) }
// still dosen't exist... we have a problem
if !os.dir_exists(gen_vc.options.work_dir) {
if !os.is_dir(gen_vc.options.work_dir) {
gen_vc.logger.error('error creating directory: $gen_vc.options.work_dir')
gen_vc.gen_error = true
return
@ -211,12 +211,12 @@ fn (gen_vc mut GenVC) generate() {
// cd to gen_vc dir
os.chdir(gen_vc.options.work_dir)
// if we are not running with the --serve flag (webhook server)
// rather than deleting and re-downloading the repo each time
// first check to see if the local v repo is behind master
// if it isn't behind theres no point continuing further
if !gen_vc.options.serve && os.dir_exists(git_repo_dir_v) {
if !gen_vc.options.serve && os.is_dir(git_repo_dir_v) {
gen_vc.cmd_exec('git -C $git_repo_dir_v checkout master')
// fetch the remote repo just in case there are newer commits there
gen_vc.cmd_exec('git -C $git_repo_dir_v fetch')
@ -229,11 +229,11 @@ fn (gen_vc mut GenVC) generate() {
// delete repos
gen_vc.purge_repos()
// clone repos
gen_vc.cmd_exec('git clone --depth 1 https://$git_repo_v $git_repo_dir_v')
gen_vc.cmd_exec('git clone --depth 1 https://$git_repo_vc $git_repo_dir_vc')
// get output of git log -1 (last commit)
git_log_v := gen_vc.cmd_exec('git -C $git_repo_dir_v log -1 --format="commit %H%nDate: %ci%nDate Unix: %ct"')
git_log_vc := gen_vc.cmd_exec('git -C $git_repo_dir_vc log -1 --format="Commit %H%nDate: %ci%nDate Unix: %ct"')
@ -241,7 +241,7 @@ fn (gen_vc mut GenVC) generate() {
// date of last commit in each repo
ts_v := git_log_v.find_between('Date:', '\n').trim_space()
ts_vc := git_log_vc.find_between('Date:', '\n').trim_space()
// parse time as string to time.Time
last_commit_time_v := time.parse(ts_v)
last_commit_time_vc := time.parse(ts_vc)
@ -259,7 +259,7 @@ fn (gen_vc mut GenVC) generate() {
gen_vc.logger.debug('last commit time ($git_repo_v): ' + last_commit_time_v.format_ss())
gen_vc.logger.debug('last commit time ($git_repo_vc): ' + last_commit_time_vc.format_ss())
gen_vc.logger.debug('last commit hash ($git_repo_v): $last_commit_hash_v')
// if vc repo already has a newer commit than the v repo, assume it's up to date
if t_unix_vc >= t_unix_v {
gen_vc.logger.warn('vc repository is already up to date.')
@ -271,7 +271,7 @@ fn (gen_vc mut GenVC) generate() {
v_exec := '$git_repo_dir_v/v'
// check if make was successful
gen_vc.assert_file_exists_and_is_not_too_short(v_exec, err_msg_make)
// build v.c for each os
for os_name in vc_build_oses {
vc_suffix := if os_name == 'nix' { '' } else { '_${os_name[..3]}' }
@ -292,7 +292,7 @@ fn (gen_vc mut GenVC) generate() {
}
// check if the vc repo actually changed
git_status := gen_vc.cmd_exec('git -C $git_repo_dir_vc status')
git_status := gen_vc.cmd_exec('git -C $git_repo_dir_vc status')
if git_status.contains('nothing to commit') {
gen_vc.logger.error('no changes to vc repo: something went wrong.')
gen_vc.gen_error = true
@ -349,12 +349,12 @@ fn (gen_vc mut GenVC) command_execute_dry(cmd string) string {
fn (gen_vc mut GenVC) purge_repos() {
// delete old repos (better to be fully explicit here, since these are destructive operations)
mut repo_dir := '$gen_vc.options.work_dir/$git_repo_dir_v'
if os.dir_exists(repo_dir) {
if os.is_dir(repo_dir) {
gen_vc.logger.info('purging local repo: "$repo_dir"')
gen_vc.cmd_exec('rm -rf $repo_dir')
}
repo_dir = '$gen_vc.options.work_dir/$git_repo_dir_vc'
if os.dir_exists(repo_dir) {
if os.is_dir(repo_dir) {
gen_vc.logger.info('purging local repo: "$repo_dir"')
gen_vc.cmd_exec('rm -rf $repo_dir')
}
@ -362,7 +362,7 @@ fn (gen_vc mut GenVC) purge_repos() {
// check if file size is too short
fn (gen_vc mut GenVC) assert_file_exists_and_is_not_too_short(f string, emsg string){
if !os.file_exists(f) {
if !os.exists(f) {
gen_vc.logger.error('$err_msg_build: $emsg .')
gen_vc.gen_error = true
return

View File

@ -94,7 +94,7 @@ pub fn (ts mut TestSession) test() {
pub fn vlib_should_be_present( parent_dir string ) {
vlib_dir := filepath.join( parent_dir, 'vlib' )
if !os.dir_exists( vlib_dir ){
if !os.is_dir( vlib_dir ){
eprintln('$vlib_dir is missing, it must be next to the V executable')
exit(1)
}

View File

@ -152,7 +152,7 @@ fn get_vmodules_dir_path() string {
fn ensure_vmodules_dir_exist() {
home_vmodules := get_vmodules_dir_path()
if !os.dir_exists( home_vmodules ) {
if !os.is_dir( home_vmodules ) {
println('Creating $home_vmodules/ ...')
os.mkdir(home_vmodules) or { panic(err) }
}

View File

@ -200,7 +200,7 @@ fn print_output(s os.Result) {
}
fn main() {
if os.args.len < 2 || !os.file_exists(os.args[1]) {
if os.args.len < 2 || !os.exists(os.args[1]) {
println('Usage:')
println(' vrepl vexepath\n')
println(' ... where vexepath is the full path to the v executable file')

View File

@ -26,7 +26,7 @@ fn v_test_compiler(vargs string){
os.chdir( parent_dir )
/*
if !os.file_exists(parent_dir + '/v.v') {
if !os.exists(parent_dir + '/v.v') {
eprintln('v.v is missing, it must be next to the V executable')
exit(1)
}
@ -34,7 +34,7 @@ fn v_test_compiler(vargs string){
// Make sure v.c can be compiled without warnings
$if mac {
if os.file_exists('/v.v') {
if os.exists('/v.v') {
os.system('$vexe -o v.c v.v')
if os.system('cc -Werror v.c') != 0 {
eprintln('cc failed to build v.c without warnings')
@ -63,7 +63,7 @@ fn v_test_compiler(vargs string){
if ret != 0 {
eprintln('failed to run v install')
}
if !os.file_exists(v_modules_path + '/nedpals/args') {
if !os.exists(v_modules_path + '/nedpals/args') {
eprintln('v failed to install a test module')
}
vmark.stop()

View File

@ -32,11 +32,11 @@ pub fn main() {
mut ts := testing.new_test_sesion(args_before)
for targ in args_after.split(' ') {
if os.file_exists(targ) && targ.ends_with('_test.v') {
if os.exists(targ) && targ.ends_with('_test.v') {
ts.files << targ
continue
}
if os.dir_exists(targ) {
if os.is_dir(targ) {
// Fetch all tests from the directory
ts.files << os.walk_ext( targ.trim_right(os.path_separator), '_test.v')
continue

View File

@ -8,7 +8,7 @@ fn main() {
println(s.output)
$if windows {
v_backup_file := '$vroot/v_old.exe'
if os.file_exists( v_backup_file ) {
if os.exists( v_backup_file ) {
os.rm( v_backup_file )
}
os.mv_by_cp('$vroot/v.exe', v_backup_file) or { panic(err) }