Skip to content

Commit

Permalink
handle the removing of the old ~/.vmodules/cache folder automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Oct 10, 2024
1 parent 9fc4e7f commit fba2e37
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions vlib/v/vcache/vcache.v
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,25 @@ pub mut:
k2cpath map[string]string // key -> filesystem cache path for the object
}

pub fn new_cache_manager(opts []string) CacheManager {
mut vcache_basepath := os.getenv('VCACHE')
if vcache_basepath == '' {
vcache_basepath = os.join_path(os.vmodules_dir(), '.cache') // use a path, that would not conflict with a user installable module
fn remove_old_cache_folder() {
// TODO: remove this after bootstrapping the new .cache location, i.e. after 2024-12-01
old_cache_folder := os.join_path(os.vmodules_dir(), 'cache')
if os.exists(old_cache_folder) {
old_readme_file := os.join_path(old_cache_folder, 'README.md')
if os.file_size(old_readme_file) == 254 {
os.rmdir_all(old_cache_folder) or {}
dlog(@FN, 'old_cache_folder: ${old_cache_folder}')
}
}
}

pub fn new_cache_manager(opts []string) CacheManager {
// use a path, that would not conflict with a user installable module. `import .cache` is not valid, => better than just `cache`:
vcache_basepath := os.getenv_opt('VCACHE') or { os.join_path(os.vmodules_dir(), '.cache') }
nlog(@FN, 'vcache_basepath: ${vcache_basepath}\n opts: ${opts}\n os.args: ${os.args.join(' ')}')
dlog(@FN, 'vcache_basepath: ${vcache_basepath} | opts:\n ${opts}')
if !os.is_dir(vcache_basepath) {
remove_old_cache_folder()
os.mkdir_all(vcache_basepath, mode: 0o700) or { panic(err) } // keep directory private
dlog(@FN, 'created folder:\n ${vcache_basepath}')
}
Expand Down

0 comments on commit fba2e37

Please sign in to comment.