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

Drop uuid and just use native mkdtemp #122

Merged
merged 4 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
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
15 changes: 5 additions & 10 deletions lib/firefox_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var os = require('os'),
// third-party
parseString = require('xml2js').parseString,
AdmZip = require('adm-zip'),
uuid = require('uuid'),
Finder = require('./profile_finder');

var config = {
Expand Down Expand Up @@ -151,7 +150,7 @@ function FirefoxProfile(options) {
this.profileDir = opts.destinationDirectory || this._createTempFolder();
} else {
// create copy
var tmpDir = opts.destinationDirectory || this._createTempFolder('-copy');
var tmpDir = opts.destinationDirectory || this._createTempFolder('copy-');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this to be a prefix instead of suffix due to how the API works.

This path is meant to be temporary and hidden from the user, so I'm guessing it was implemented only to improve debugging but isn't fundamental.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to not alter an existing profile directory (if provided in options.profileDir).

fs.copySync(opts.profileDirectory, tmpDir, {
clobber: true,
filter: isNotLockFile,
Expand Down Expand Up @@ -575,7 +574,7 @@ FirefoxProfile.prototype._installExtension = function (addon, cb) {
self = this;

if (addon.slice(-4) === '.xpi') {
tmpDir = this._createTempFolder(addon.split(path.sep).slice(-1));
tmpDir = this._createTempFolder(addon.split(path.sep).pop());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice returned an array. It worked before because _createTempFolder was concatenating this with +

var zip = new AdmZip(addon);
zip.extractAllTo(tmpDir, true);
xpiFile = addon;
Expand Down Expand Up @@ -713,13 +712,9 @@ FirefoxProfile.prototype._addonDetails = function (addonPath, cb) {
});
};

FirefoxProfile.prototype._createTempFolder = function (suffix) {
suffix = suffix || '';
var folderName = path.resolve(
path.join(os.tmpdir(), uuid.v4() + suffix + path.sep)
);
fs.mkdirSync(folderName);
return folderName;
FirefoxProfile.prototype._createTempFolder = function (prefix) {
// Don't use an empty string for `prefix` or it might not work on some CIs (Travis)
return fs.mkdtempSync(path.resolve(os.tmpdir(), prefix || 'firefox-profile')) + '/';
};

FirefoxProfile.prototype._sanitizePref = function (val) {
Expand Down
Loading