Write an .origin file in localized directories.

This commit is contained in:
Young Hahn 2011-05-26 14:28:22 -04:00
parent 9529575662
commit 7001b8d4bb

View File

@ -24,7 +24,9 @@ function External(env, uri, alias) {
env.local_data_dir = env.local_data_dir || '';
// If local relative path, join with local_data_dir to form an
// absolute path.
// absolute path. Save the original URI if needed for later
// reference.
this.originalUri = uri;
var local = !(/^https?:\/\//i.test(uri));
if (local && uri[0] !== '/' && env.local_data_dir) {
uri = path.join(env.local_data_dir, uri);
@ -39,7 +41,7 @@ function External(env, uri, alias) {
var hash = crypto.createHash('md5').update(uri).digest('hex');
// Temporary destination path for staging downloads, pre-processed files.
if (local) {
this.tempPath = this.uri;
this.tempPath = uri;
} else {
this.tempPath = path.join(env.tmp_dir, hash + path.extname(uri));
}
@ -85,7 +87,7 @@ External.prototype.processFile = function(local) {
},
function(err) {
if (err) throw err;
return that.processor(that.tempPath, that.path(), this);
return that.processor(that, this);
},
function(err) {
that.invokeCallbacks(err);
@ -249,7 +251,9 @@ External.destinations['.zip'] = function(destPath) {
};
External.processors = {};
External.processors['default'] = function(tempPath, destPath, callback) {
External.processors['default'] = function(ext, callback) {
var tempPath = ext.tempPath;
var destPath = ext.destPath;
path.exists(tempPath, function(exists) {
if (!exists) {
callback(new Error('File ' + tempPath + ' does not exist'));
@ -279,7 +283,10 @@ External.processors['default'] = function(tempPath, destPath, callback) {
}
});
};
External.processors['.zip'] = function(tempPath, destPath, callback) {
External.processors['.zip'] = function(ext, callback) {
var tempPath = ext.tempPath;
var destPath = ext.destPath;
var originalUri = ext.originalUri;
try {
sys.debug('unzipping file');
var zf = new zip.ZipFile(tempPath);
@ -297,8 +304,7 @@ External.processors['.zip'] = function(tempPath, destPath, callback) {
External.mkdirp(path.dirname(uncompressed), 0755, function(err) {
if (err && err.errno != constants.EEXIST) {
callback("Couldn't create directory " + path.dirname(name));
}
else {
} else {
// if just a directory skip ahead
if (!path.extname(name) || name[0] === '.') {
next();
@ -319,6 +325,11 @@ External.processors['.zip'] = function(tempPath, destPath, callback) {
});
});
},
// Write an .origin file to indicate the source of this directory.
function(err) {
if (err) throw err;
fs.writeFile(path.join(destPath, '.origin'), originalUri, this);
},
callback
);
};