centralized ensure dir

This commit is contained in:
2026-02-20 15:02:16 -06:00
24 changed files with 341 additions and 949 deletions

28
link.cm
View File

@@ -20,30 +20,8 @@ function get_packages_dir() {
return global_shop_path + '/packages'
}
// return the safe path for the package
function safe_package_path(pkg) {
// For absolute paths, replace / with _ to create a valid directory name
if (pkg && starts_with(pkg, '/'))
return replace(replace(pkg, '/', '_'), '@', '_')
return replace(pkg, '@', '_')
}
function get_package_abs_dir(package) {
return get_packages_dir() + '/' + safe_package_path(package)
}
function ensure_dir(path) {
if (fd.stat(path).isDirectory) return
var parts = array(path, '/')
var current = starts_with(path, '/') ? '/' : ''
var i = 0
for (i = 0; i < length(parts); i++) {
if (parts[i] == '') continue
current = current + parts[i] + '/'
if (!fd.stat(current).isDirectory) {
fd.mkdir(current)
}
}
return get_packages_dir() + '/' + fd.safe_package_path(package)
}
// Resolve a link target to its actual path
@@ -54,7 +32,7 @@ function resolve_link_target(target) {
return target
}
// Target is another package - resolve to its directory
return get_packages_dir() + '/' + safe_package_path(target)
return get_packages_dir() + '/' + fd.safe_package_path(target)
}
var Link = {}
@@ -194,7 +172,7 @@ Link.sync_one = function(canonical, target, shop) {
// Ensure parent directories exist
var parent = fd.dirname(target_dir)
ensure_dir(parent)
fd.ensure_dir(parent)
// Check current state
var current_link = null