40 lines
974 B
V
40 lines
974 B
V
module main
|
|
|
|
import log
|
|
import os
|
|
|
|
@[noinit]
|
|
struct Cache {
|
|
base_path string
|
|
}
|
|
|
|
fn Cache.new(base_path string) !Cache {
|
|
log.info('using cache dir: ${base_path}')
|
|
os.mkdir_all(base_path) or { return error('failed to create cache directory ${base_path}') }
|
|
|
|
return Cache{
|
|
base_path: base_path
|
|
}
|
|
}
|
|
|
|
fn Cache.default() !Cache {
|
|
base_path := os.getenv_opt('XDG_CACHE_HOME') or { os.getenv('HOME') + '.cache' }
|
|
cache_dir := os.join_path(base_path, 'setup-browser')
|
|
return Cache.new(cache_dir)
|
|
}
|
|
|
|
fn (c Cache) dir_no_create(name ...string) !string {
|
|
return os.join_path(c.base_path, ...name)
|
|
}
|
|
|
|
fn (c Cache) path(name ...string) !string {
|
|
dir := os.join_path(c.base_path, ...name)
|
|
os.mkdir_all(dir) or { return error('failed to create directory ${dir}') }
|
|
return dir
|
|
}
|
|
|
|
fn (c Cache) file(name ...string) !string {
|
|
file := os.join_path(c.base_path, ...name)
|
|
os.mkdir_all(os.dir(file)) or { return error('failed to create directory ${os.dir(file)}') }
|
|
return file
|
|
}
|