sync: wip changes

This commit is contained in:
binekrasik
2026-05-21 13:47:27 +02:00
parent 0577ee49cf
commit e0269c9b6a
7 changed files with 838 additions and 32 deletions

45
src/program/Mv.ts Normal file
View File

@@ -0,0 +1,45 @@
import { Item } from '../fs/Item'
import type { SimpleStream } from '../utils/SimpleStream'
import { Program } from './Program'
export class Mv extends Program {
constructor() {
super()
}
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
if (args.length < 3) {
stdout.emit("mv: error: missing the first and/or second path arguments\n")
return 1
}
let item1: Item
let item2: Item
try {
item1 = await Item.openDir(Item.NormalizePath(args[1].startsWith('/') ? args[1] : `${workdir.GetPath()}/${args[1]}`))
item2 = await Item.openDir(Item.NormalizePath(args[2].startsWith('/') ? args[2] : `${workdir.GetPath()}/${args[2]}`))
} catch {
item1 = await Item.open(Item.NormalizePath(args[1].startsWith('/') ? args[1] : `${workdir.GetPath()}/${args[1]}`))
item2 = await Item.open(Item.NormalizePath(args[2].startsWith('/') ? args[2] : `${workdir.GetPath()}/${args[2]}`))
}
if (await item1.Exists()) {
stdout.emit(`mv: error: source directory ${item1.GetPath()} does not exist.\n`)
return 2
}
if (await item2.Exists()) {
stdout.emit(`mv: error: destination directory ${item2.GetPath()} already exists.\n`)
return 2
}
await item2.Create()
await item1.Copy(item2)
await item1.Delete()
stdout.emit(`-> moved ${item1.GetPath()} -> ${item2.GetPath()}\n`)
return 0
}
}