Skip to content

Commit 50d14d8

Browse files
committed
Ensure apk download temp files are cleaned up correctly
1 parent 893435c commit 50d14d8

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/interceptors/android/android-adb-interceptor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ async function updateLocalApk(
9494
config: HtkConfig
9595
) {
9696
console.log(`Updating local APK to version ${version}`);
97+
9798
const {
9899
path: tmpApk,
99100
fd: tmpApkFd,
100101
cleanupCallback
101-
} = await createTmp();
102+
} = await createTmp({ keep: true });
102103

103104
const tmpApkStream = fs.createWriteStream(tmpApk, {
104105
fd: tmpApkFd,
@@ -123,11 +124,11 @@ async function updateLocalApk(
123124

124125
await renameFile(tmpApk, path.join(config.configPath, `httptoolkit-${version}.apk`));
125126
console.log(`Local APK moved to ${path.join(config.configPath, `httptoolkit-${version}.apk`)}`);
126-
await cleanupLocalApks(config);
127+
await cleanupOldApks(config);
127128
}
128129

129130
// Delete all but the most recent APK version in the config directory.
130-
async function cleanupLocalApks(config: HtkConfig) {
131+
async function cleanupOldApks(config: HtkConfig) {
131132
const apks = (await readDir(config.configPath))
132133
.map(filename => filename.match(/^httptoolkit-(.*).apk$/))
133134
.filter((match): match is RegExpMatchArray => !!match)

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ export const deleteFolder = promisify(rimraf);
6666
export const ensureDirectoryExists = (path: string) =>
6767
checkAccess(path).catch(() => mkDir(path, { recursive: true }));
6868

69-
export const createTmp = () => new Promise<{
69+
export const createTmp = (options: tmp.Options = {}) => new Promise<{
7070
path: string,
7171
fd: number,
7272
cleanupCallback: () => void
7373
}>((resolve, reject) => {
74-
tmp.file((err, path, fd, cleanupCallback) => {
74+
tmp.file(options, (err, path, fd, cleanupCallback) => {
7575
if (err) return reject(err);
7676
resolve({ path, fd, cleanupCallback });
7777
});

0 commit comments

Comments
 (0)