Skip to content

Commit

Permalink
Merge branch 'master' into nj/issue-5159-better
Browse files Browse the repository at this point in the history
  • Loading branch information
Narciso Jaramillo committed Sep 27, 2013
2 parents 34f8a42 + 78c87c4 commit 3ff1006
Show file tree
Hide file tree
Showing 87 changed files with 2,587 additions and 5,617 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ module.exports = function (grunt) {
shell: {
repo: grunt.option("shell-repo") || "../brackets-shell",
mac: "<%= shell.repo %>/installer/mac/staging/<%= pkg.name %>.app",
win: "<%= shell.repo %>/installer/win/staging/<%= pkg.name %>.exe"
win: "<%= shell.repo %>/installer/win/staging/<%= pkg.name %>.exe",
linux: "<%= shell.repo %>/installer/linux/debian/package-root/opt/brackets/brackets"
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ define(function (require, exports, module) {
if (brackets.nativeMenus) {
$("body").addClass("has-appshell-menus");
} else {
// Prevent the menu item to grab the focus -- override focus implementation
// (issue #5310) workaround for bootstrap dropdown: prevent the menu item to grab
// the focus -- override jquery focus implementation for top-level menu items
(function () {
var defaultFocus = $.fn.focus;
$.fn.focus = function () {
Expand Down
6 changes: 5 additions & 1 deletion src/extensibility/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ define(function (require, exports, module) {
*/
function formatError(error) {
function localize(key) {
return Strings[key] || Strings.UNKNOWN_ERROR;
if (Strings[key]) {
return Strings[key];
}
console.log("Unknown installation error", key);
return Strings.UNKNOWN_ERROR;
}

if (Array.isArray(error)) {
Expand Down
61 changes: 27 additions & 34 deletions src/extensibility/node/ExtensionManagerDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ var semver = require("semver"),
request = require("request"),
os = require("os"),
fs = require("fs-extra"),
temp = require("temp"),
validate = require("./package-validator").validate;

// Automatically clean up temp files on exit
temp.track();

var Errors = {
API_NOT_COMPATIBLE: "API_NOT_COMPATIBLE",
Expand Down Expand Up @@ -102,7 +105,6 @@ function _performInstall(packagePath, installDirectory, validationResult, callba
fs.copy(sourceDir, installDirectory, function (err) {
if (err) {
_removeFailedInstallation(installDirectory);
fs.remove(validationResult.extractDir);
callback(err, null);
} else {
// The status may have already been set previously (as in the
Expand Down Expand Up @@ -217,10 +219,21 @@ function _cmdInstall(packagePath, destinationDirectory, options, callback, _doUp

var validateCallback = function (err, validationResult) {
validationResult.localPath = packagePath;

// This is a wrapper for the callback that will delete the temporary
// directory to which the package was unzipped.
function deleteTempAndCallback(err) {
if (validationResult.extractDir) {
fs.remove(validationResult.extractDir);
delete validationResult.extractDir;
}
callback(err, validationResult);
}

// If there was trouble at the validation stage, we stop right away.
if (err || validationResult.errors.length > 0) {
validationResult.installationStatus = Statuses.FAILED;
callback(err, validationResult);
deleteTempAndCallback(err, validationResult);
return;
}

Expand Down Expand Up @@ -251,7 +264,7 @@ function _cmdInstall(packagePath, destinationDirectory, options, callback, _doUp
installDirectory = path.join(options.disabledDirectory, extensionName);
validationResult.installationStatus = Statuses.DISABLED;
validationResult.disabledReason = Errors.API_NOT_COMPATIBLE;
_removeAndInstall(packagePath, installDirectory, validationResult, callback);
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
return;
}
}
Expand All @@ -271,25 +284,25 @@ function _cmdInstall(packagePath, destinationDirectory, options, callback, _doUp
// both legacy and new extensions installed.
fs.remove(legacyDirectory, function (err) {
if (err) {
callback(err);
deleteTempAndCallback(err, validationResult);
return;
}
_removeAndInstall(packagePath, installDirectory, validationResult, callback);
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
});
} else {
_removeAndInstall(packagePath, installDirectory, validationResult, callback);
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
}
} else if (hasLegacyPackage) {
validationResult.installationStatus = Statuses.NEEDS_UPDATE;
validationResult.name = guessedName;
callback(null, validationResult);
deleteTempAndCallback(null, validationResult);
} else {
_checkExistingInstallation(validationResult, installDirectory, systemInstallDirectory, callback);
_checkExistingInstallation(validationResult, installDirectory, systemInstallDirectory, deleteTempAndCallback);
}
} else {
// Regular installation with no conflicts.
validationResult.disabledReason = null;
_performInstall(packagePath, installDirectory, validationResult, callback);
_performInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
}
};

Expand Down Expand Up @@ -329,26 +342,6 @@ function _cmdUpdate(packagePath, destinationDirectory, options, callback) {
_cmdInstall(packagePath, destinationDirectory, options, callback, true);
}

/**
* Creates a uniquely-named file in the OS temp directory and opens it for writing.
* @return {{localPath: string, outStream: WriteStream}}
*/
function _createTempFile() {
var root = os.tmpDir();
var pathPrefix = root + "/brackets.download";
var suffix = 1;
while (fs.existsSync(pathPrefix + suffix) && suffix < 100) {
suffix++;
}
if (suffix === 100) {
return null;
}

var localPath = pathPrefix + suffix;
var outStream = fs.createWriteStream(localPath);
return { outStream: outStream, localPath: localPath };
}

/**
* Wrap up after the given download has terminated (successfully or not). Closes connections, calls back the
* client's callback, and IF there was an error, delete any partially-downloaded file.
Expand Down Expand Up @@ -409,15 +402,15 @@ function _cmdDownloadFile(downloadId, url, callback) {
return;
}

var tempFileInfo = _createTempFile();
if (!tempFileInfo) {
var stream = temp.createWriteStream("brackets");
if (!stream) {
_endDownload(downloadId, Errors.CANNOT_WRITE_TEMP);
return;
}
pendingDownloads[downloadId].localPath = tempFileInfo.localPath;
pendingDownloads[downloadId].outStream = tempFileInfo.outStream;
pendingDownloads[downloadId].localPath = stream.path;
pendingDownloads[downloadId].outStream = stream;

tempFileInfo.outStream.write(body);
stream.write(body);
_endDownload(downloadId);
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading

0 comments on commit 3ff1006

Please sign in to comment.