Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve copy promises #2038

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 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,12 +61,23 @@ export class Cp {
file: tmpFileName,
cwd: tgtPath,
});
resolve();
if (!resolved) {
resolved = true;
resolve();
}
} catch (e) {
reject(e);
}
},
)
.then((conn) => {
conn.on('close', () => {
if (!resolved) {
resolved = true;
resolve();
}
});
})
.catch(reject);
});
}
Expand All @@ -91,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 @@ -111,10 +124,21 @@ export class Cp {
),
);
} else {
resolve();
if (!resolved) {
resolved = true;
resolve();
}
}
},
)
.then((conn) => {
conn.on('close', () => {
if (!resolved) {
resolved = true;
resolve();
}
});
})
.catch(reject);
});
}
Expand Down