fix(mod_unpack): handle partial readdir results from signal-interrupted getdents64 when unpacking to ensure sibling removal and nested moves complete
This commit is contained in:
@@ -108,20 +108,28 @@ export class TsUnpacker {
|
||||
const nestedPath = this.getNestedPath();
|
||||
|
||||
// Step 1: Remove sibling entries (everything in dest except the source folder)
|
||||
const destEntries = await fs.promises.readdir(this.destDir);
|
||||
for (const entry of destEntries) {
|
||||
if (entry !== this.sourceFolderName) {
|
||||
await fs.promises.rm(path.join(this.destDir, entry), { recursive: true, force: true });
|
||||
// Loop handles partial readdir results from signal-interrupted getdents64
|
||||
let destEntries = await fs.promises.readdir(this.destDir);
|
||||
while (destEntries.some(e => e !== this.sourceFolderName)) {
|
||||
for (const entry of destEntries) {
|
||||
if (entry !== this.sourceFolderName) {
|
||||
await fs.promises.rm(path.join(this.destDir, entry), { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
destEntries = await fs.promises.readdir(this.destDir);
|
||||
}
|
||||
|
||||
// Step 2: Move all contents from nested dir up to dest dir
|
||||
const nestedEntries = await fs.promises.readdir(nestedPath);
|
||||
for (const entry of nestedEntries) {
|
||||
await fs.promises.rename(
|
||||
path.join(nestedPath, entry),
|
||||
path.join(this.destDir, entry),
|
||||
);
|
||||
// Loop handles partial readdir results from signal-interrupted getdents64
|
||||
let nestedEntries = await fs.promises.readdir(nestedPath);
|
||||
while (nestedEntries.length > 0) {
|
||||
for (const entry of nestedEntries) {
|
||||
await fs.promises.rename(
|
||||
path.join(nestedPath, entry),
|
||||
path.join(this.destDir, entry),
|
||||
);
|
||||
}
|
||||
nestedEntries = await fs.promises.readdir(nestedPath);
|
||||
}
|
||||
|
||||
// Step 3: Remove the now-empty nested directory
|
||||
|
||||
Reference in New Issue
Block a user