Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Checks path to archive before processing
Browse files Browse the repository at this point in the history
  • Loading branch information
cdelcol authored and ejzn committed Nov 5, 2012
1 parent bbdd2ae commit 7fbf0d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/file-manager.js
Expand Up @@ -108,10 +108,14 @@ function prepare(session) {
}

// unzip archive
if (session.archivePath.toLowerCase().match("[.]zip$")) {
unzip(session.archivePath, session.sourceDir);
if (path.existsSync(session.archivePath)) {
if (session.archivePath.toLowerCase().match("[.]zip$")) {
unzip(session.archivePath, session.sourceDir);
} else {
copyDirContents(session.archivePath, session.sourceDir);
}
} else {
copyDirContents(session.archivePath, session.sourceDir);
throw localize.translate("EXCEPTION_INVALID_ARCHIVE_PATH", session.archivePath);
}

//test for existing webworks.js files
Expand Down
3 changes: 3 additions & 0 deletions lib/localize.js
Expand Up @@ -174,6 +174,9 @@ var Localize = require("localize"),
},
"WARN_WEBPLATFORM_I18N_PACKAGED" : {
"en": "i18n.js has been packaged as an alternative to the on device version"
},
"EXCEPTION_INVALID_ARCHIVE_PATH" : {
"en": "An archive or directory does not exist at the path specified: \"$[1]\""
}

}, "", ""); // TODO maybe a bug in localize, must set default locale to "" in order get it to work
Expand Down
10 changes: 10 additions & 0 deletions test/unit/lib/file-manager.js
Expand Up @@ -10,6 +10,7 @@ var srcPath = __dirname + "/../../../lib/",
conf = require(srcPath + "conf"),
fileMgr = require(srcPath + "file-manager"),
testData = require("./test-data"),
testUtilities = require("./test-utilities"),
session = testData.session,
extManager = {
getAllExtensionsToCopy: function (accessList) {
Expand Down Expand Up @@ -257,4 +258,13 @@ describe("File manager", function () {
expect(path.existsSync(session.sourcePaths.LIB)).toBeTruthy();
});

it("prepareOutputFiles() should throw an error if the archive path doesn't exist", function () {
spyOn(wrench, "copyDirSyncRecursive");
var tempSession = testUtilities.cloneObj(session);
tempSession.archivePath = path.resolve("test/non-existant.zip");
expect(function () {
fileMgr.prepareOutputFiles(tempSession);
}).toThrow(localize.translate("EXCEPTION_INVALID_ARCHIVE_PATH", tempSession.archivePath));
});

});

0 comments on commit 7fbf0d3

Please sign in to comment.