Skip to content

Commit

Permalink
Fix tmp file name clash when writing entitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete committed Nov 2, 2023
1 parent a521c58 commit 48f66d6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ class Applesign {
return result;
}

_pathInTmp (filePath, scope = null) {
const baseName = path.basename(filePath);
if (typeof scope === 'string') {
return path.join(this.tmpDir, scope, baseName);
}
return path.join(this.tmpDir, baseName);
_fullPathInTmp (filePath) {
const dirname = path.dirname(filePath);
const dirnameInTmp = path.join(this.tmpDir, dirname);
fs.mkdirpSync(dirnameInTmp);
return path.join(this.tmpDir, filePath);
}

async getDeviceProvision () {
Expand Down Expand Up @@ -337,7 +336,7 @@ class Applesign {
// TODO: merge additional entitlements here
const newEntitlements = plistBuild(entMacho).toString();
const newEntitlementsFile = file + '.entitlements';
const tmpEntitlementsFile = this._pathInTmp(newEntitlementsFile);
const tmpEntitlementsFile = this._fullPathInTmp(newEntitlementsFile);
fs.writeFileSync(tmpEntitlementsFile, newEntitlements);
this.config.entitlement = tmpEntitlementsFile;
return;
Expand All @@ -361,7 +360,7 @@ class Applesign {
this.emit('message', 'Using an unsigned provisioning');
const newEntitlementsFile = file + '.entitlements';
const newEntitlements = plistBuild(entMacho).toString();
const tmpEntitlementsFile = this._pathInTmp(newEntitlementsFile);
const tmpEntitlementsFile = this._fullPathInTmp(newEntitlementsFile);
fs.writeFileSync(tmpEntitlementsFile, newEntitlements);
this.config.entitlement = tmpEntitlementsFile;
if (!this.config.noEntitlementsFile) {
Expand Down Expand Up @@ -497,7 +496,7 @@ class Applesign {

this.debugInfo(file, 'newEntitlements', ent);

const tmpEntitlementsFile = this._pathInTmp(newEntitlementsFile);
const tmpEntitlementsFile = this._fullPathInTmp(newEntitlementsFile);
fs.writeFileSync(tmpEntitlementsFile, newEntitlements);
this.config.entitlement = tmpEntitlementsFile;
if (!this.config.noEntitlementsFile) {
Expand Down Expand Up @@ -562,7 +561,7 @@ class Applesign {
if (this.config.cloneEntitlements) {
const mp = await tools.getMobileProvisionPlist(this.config.mobileprovision);
const newEntitlementsFile = file + '.entitlements';
const tmpEntitlementsFile = this._pathInTmp(newEntitlementsFile);
const tmpEntitlementsFile = this._fullPathInTmp(newEntitlementsFile);
const entstr = plistBuild(mp.Entitlements, { pretty: true, allowEmpty: false }).toString();
fs.writeFileSync(tmpEntitlementsFile, entstr);
entitlements = tmpEntitlementsFile;
Expand All @@ -572,7 +571,7 @@ class Applesign {
let res;
if (this.config.pseudoSign) {
const newEntitlementsFile = file + '.entitlements';
const tmpEntitlementsFile = this._pathInTmp(newEntitlementsFile);
const tmpEntitlementsFile = this._fullPathInTmp(newEntitlementsFile);
const entitlements = fs.existsSync(tmpEntitlementsFile) ? tmpEntitlementsFile : null;
res = await tools.pseudoSign(entitlements, file);
} else {
Expand Down

0 comments on commit 48f66d6

Please sign in to comment.