Skip to content

Commit

Permalink
use cwd as temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiChou committed Mar 5, 2024
1 parent c096486 commit bab0de9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EventEmitter } from 'events';
import { mkdir, open, rm, rename } from 'fs/promises';
import { tmpdir } from 'os';
import { mkdir, open, rm, rmdir, rename } from 'fs/promises';
import { basename, join, resolve } from 'path';

import { AppBundleVisitor } from './lib/scan.js';
Expand Down Expand Up @@ -248,7 +247,8 @@ export class BagBak extends EventEmitter {
* @returns {Promise<string>} final path of ipa
*/
async pack(suggested) {
const payload = join(tmpdir(), 'bagbak', this.bundle, 'Payload');
const DIR_NAME = '.bagbak'; // do not use tmpdir here, because sometimes it might be in different partition
const payload = join(DIR_NAME, this.bundle, 'Payload');
await rm(payload, { recursive: true, force: true });
await mkdir(payload, { recursive: true });
await this.dump(payload, true);
Expand All @@ -272,6 +272,17 @@ export class BagBak extends EventEmitter {
debug('Created zip archive', z);
await rename(z, ipa);

{
// remove artifact
const artifact = join(DIR_NAME, this.bundle);
await rm(artifact, { recursive: true, force: true })
.catch(error => {
debug(`Warning: failed to remove artifact directory ${artifact}`, error);
})
.then(() => rmdir(DIR_NAME))
.catch(_ => { /* ignore */ });
}

return ipa;
}
}

0 comments on commit bab0de9

Please sign in to comment.