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

os, filepath: reorganize functions

This commit is contained in:
Alexey
2019-12-23 13:09:22 +03:00
committed by Alexander Medvednikov
parent 6e130cd446
commit dced76d1a4
28 changed files with 174 additions and 98 deletions

View File

@@ -169,7 +169,7 @@ pub fn cp_r(osource_path, odest_path string, overwrite bool) ?bool {
}
// single file copy
if !os.is_dir(source_path) {
adjasted_path := if os.is_dir(dest_path) { filepath.join(dest_path,os.filename(source_path)) } else { dest_path }
adjasted_path := if os.is_dir(dest_path) { filepath.join(dest_path,filepath.filename(source_path)) } else { dest_path }
if os.exists(adjasted_path) {
if overwrite {
os.rm(adjasted_path)
@@ -611,40 +611,28 @@ fn print_c_errno() {
// C.printf('errno=%d err="%s"\n', C.errno, C.strerror(C.errno))
}
[deprecated]
pub fn ext(path string) string {
pos := path.last_index('.') or {
return ''
}
return path[pos..]
println('Use filepath.ext')
return filepath.ext(path)
}
// dir returns all but the last element of path, typically the path's directory.
[deprecated]
pub fn dir(path string) string {
if path == '.' {
return getwd()
}
pos := path.last_index(path_separator) or {
return '.'
}
return path[..pos]
}
fn path_sans_ext(path string) string {
pos := path.last_index('.') or {
return path
}
return path[..pos]
println('Use filepath.dir')
return filepath.ext(path)
}
[deprecated]
pub fn basedir(path string) string {
pos := path.last_index(path_separator) or {
return path
}
return path[..pos] // NB: *without* terminating /
println('Use filepath.basedir')
return filepath.basedir(path)
}
[deprecated]
pub fn filename(path string) string {
return path.all_after(path_separator)
println('Use filepath.filename')
return filepath.filename(path)
}
// get_line returns a one-line string from stdin

View File

@@ -88,15 +88,6 @@ fn test_create_and_delete_folder() {
assert folder_exists == false
}
fn test_dir() {
$if windows {
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'
} $else {
assert os.dir('/var/tmp/foo') == '/var/tmp'
}
}
fn walk_callback(file string) {
if file == '.' || file == '..' {
return