2022-11-03 10:24:52 +03:00
|
|
|
import os
|
2020-04-05 00:37:13 +03:00
|
|
|
|
|
|
|
const (
|
|
|
|
// tfolder will contain all the temporary files/subfolders made by
|
|
|
|
// the different tests. It would be removed in testsuite_end(), so
|
|
|
|
// individual os tests do not need to clean up after themselves.
|
2022-11-03 10:24:52 +03:00
|
|
|
tfolder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'inode_test')
|
2020-04-05 00:37:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
fn testsuite_begin() {
|
2022-11-03 10:24:52 +03:00
|
|
|
eprintln('testsuite_begin, tfolder = $tfolder')
|
|
|
|
os.rmdir_all(tfolder) or {}
|
|
|
|
assert !os.is_dir(tfolder)
|
|
|
|
os.mkdir_all(tfolder) or { panic(err) }
|
|
|
|
os.chdir(tfolder) or {}
|
|
|
|
assert os.is_dir(tfolder)
|
2020-04-05 00:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn testsuite_end() {
|
2022-11-03 10:24:52 +03:00
|
|
|
os.chdir(os.wd_at_startup) or {}
|
|
|
|
os.rmdir_all(tfolder) or { panic(err) }
|
|
|
|
assert !os.is_dir(tfolder)
|
2020-04-05 00:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_inode_file_type() {
|
|
|
|
filename := './test1.txt'
|
2022-11-03 10:24:52 +03:00
|
|
|
mut file := os.open_file(filename, 'w', 0o600) or { return }
|
2020-06-01 18:30:17 +03:00
|
|
|
file.close()
|
2022-11-03 10:24:52 +03:00
|
|
|
mode := os.inode(filename)
|
|
|
|
os.rm(filename) or { panic(err) }
|
2020-04-05 00:37:13 +03:00
|
|
|
assert mode.typ == .regular
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_inode_file_owner_permission() {
|
|
|
|
filename := './test2.txt'
|
2022-11-03 10:24:52 +03:00
|
|
|
mut file := os.open_file(filename, 'w', 0o600) or { return }
|
2020-06-01 18:30:17 +03:00
|
|
|
file.close()
|
2022-11-03 10:24:52 +03:00
|
|
|
mode := os.inode(filename)
|
|
|
|
os.rm(filename) or {}
|
2020-04-05 00:37:13 +03:00
|
|
|
assert mode.owner.read
|
|
|
|
assert mode.owner.write
|
|
|
|
assert !mode.owner.execute
|
|
|
|
}
|
2022-02-01 15:49:06 +03:00
|
|
|
|
|
|
|
fn test_inode_file_permissions_bitmask() {
|
2022-11-03 10:24:52 +03:00
|
|
|
if os.user_os() == 'windows' {
|
2022-02-01 15:49:06 +03:00
|
|
|
println('> skipping ${@FN} on windows')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
filename := './test3.txt'
|
2022-11-03 10:24:52 +03:00
|
|
|
mut file := os.open_file(filename, 'w', 0o641) or { return }
|
2022-02-01 15:49:06 +03:00
|
|
|
file.close()
|
2022-11-03 10:24:52 +03:00
|
|
|
mode := os.inode(filename)
|
|
|
|
os.rm(filename) or {}
|
2022-02-01 15:49:06 +03:00
|
|
|
assert mode.bitmask() == 0o641
|
|
|
|
}
|