Skip to content

Commit

Permalink
Don't resolve twice
Browse files Browse the repository at this point in the history
  • Loading branch information
sjawhar committed Nov 29, 2024
1 parent eef93d6 commit 5fc727f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/cp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Cp {
command.push(srcPath);
const writerStream = fs.createWriteStream(tmpFileName);
const errStream = new WritableStreamBuffer();
let resolved = false;
return new Promise<void>((resolve, reject) => {
this.execInstance
.exec(
Expand All @@ -60,15 +61,21 @@ export class Cp {
file: tmpFileName,
cwd: tgtPath,
});
resolve();
if (!resolved) {
resolved = true;
resolve();
}
} catch (e) {
reject(e);
}
},
)
.then((conn) => {
conn.on('close', () => {
resolve();
if (!resolved) {
resolved = true;
resolve();
}
});
})
.catch(reject);
Expand Down Expand Up @@ -96,6 +103,7 @@ export class Cp {
await tar.c({ file: tmpFileName, cwd }, [srcPath]);
const readStream = fs.createReadStream(tmpFileName);
const errStream = new WritableStreamBuffer();
let resolved = false;
return new Promise<void>((resolve, reject) => {
this.execInstance
.exec(
Expand All @@ -116,13 +124,19 @@ export class Cp {
),
);
} else {
resolve();
if (!resolved) {
resolved = true;
resolve();
}
}
},
)
.then((conn) => {
conn.on('close', () => {
resolve();
if (!resolved) {
resolved = true;
resolve();
}
});
})
.catch(reject);
Expand Down

0 comments on commit 5fc727f

Please sign in to comment.