193
*/
194
export function buildCleanupOldCLIsCommand(serverDataFolderName: string, quality: string): string {
196
>
const archive = getRemoteCLIArchiveName(quality);
197
>
const commitGlob = '[0-9a-f]'.repeat(40);
198
>
// `ls -1t` sorts by mtime newest-first on both Linux (coreutils) and
199
>
// macOS (BSD). `awk 'NR>5'` drops the 5 most recent entries we want to
200
>
// keep. `xargs -I{} rm -f -- {}` is one-rm-per-line — slow but safe
201
>
// against whitespace splitting and option injection, and a no-op when
202
>
// input is empty on both BSDs and GNU.
203
>
return `ls -1t -- ${root}/${archive}-${commitGlob} 2>/dev/null | awk 'NR>5' | xargs -I{} rm -f -- {} 2>/dev/null; true`;
204
>
}
205
206
/**