Files
bare-operating-system/packages/bare-os-booter/lib/p2p/bare-os-replication-priority.js
T
2026-08-18 18:11:28 -04:00

23 lines
670 B
JavaScript

/**
* Lexicographic replication priority tiers (boot-critical paths first).
* @param {string[]} paths
*/
export function prioritizeReplicationPaths(paths) {
const boot = ['/boot/', '/etc/bare-os/', '/lib/bare-os/', '/bin/']
/** @type {{ path: string, tier: number }[]} */
const scored = []
for (const p of paths) {
const path = String(p || '').replace(/\\/g, '/')
let tier = 99
for (let i = 0; i < boot.length; i++) {
if (path.startsWith(boot[i])) {
tier = i
break
}
}
scored.push({ path, tier })
}
scored.sort((a, b) => a.tier - b.tier || a.path.localeCompare(b.path))
return scored.map((s) => s.path)
}