chore: fix path syntax in core programs

This commit is contained in:
binekrasik
2026-05-19 23:19:36 +02:00
parent 1d00cf6deb
commit b5089251ff
9 changed files with 42 additions and 51 deletions

View File

@@ -8,10 +8,14 @@ export class Ls extends Program {
}
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
// open the target directory, default to workdir
const item = args[1]
? await Item.openDir(args[1].startsWith('/')
? args[1]
: `${workdir.GetPath()}${workdir.GetPath().endsWith('/') ? '' : '/'}${args[1]}`)
? await Item.openDir(Item.NormalizePath(
args[1].startsWith('/')
? args[1]
: `${workdir.GetPath()}/${args[1]}`
))
: workdir
if (args[1] && !item.IsDirectory()) {
@@ -25,10 +29,10 @@ export class Ls extends Program {
}
stdout.emit(`-> Listing contents of item: '${item.GetPath()}'\n`)
stdout.emit(` [ drwx name ]\n`)
stdout.emit(` [ drwx name ]\n`)
const items = await item.List()
items.forEach(entry => {
stdout.emit(` | ${`${(entry.IsDirectory() ? 'd' : '-')}${(entry.IsReadable() ? 'r' : '-')}${(entry.IsWritable() ? 'w' : '-')}${(entry.IsExecutable() ? 'x' : '-')}`.padEnd(8, ' ')} '${entry.GetName()}'\n`)
stdout.emit(` | ${`${(entry.IsDirectory() ? 'd' : '-')}${(entry.IsReadable() ? 'r' : '-')}${(entry.IsWritable() ? 'w' : '-')}${(entry.IsExecutable() ? 'x' : '-')}`.padEnd(8, ' ')} ${entry.GetName()}\n`)
})
return 0