Fixes renaming between disks problem in linux

According to https://github.com/joyent/node/issues/2703
fs.rename does not support renaming between disks, which
is causing a problem when the /tmp directory is not on the
same disk as the cwd.

This is an ugly fix involving error catching, but I would
love some input to see how to fix this problem permanently
This commit is contained in:
Nathan Bleigh
2012-09-11 17:38:12 -05:00
parent 4527f76718
commit dbcea61300

View File

@@ -125,16 +125,29 @@ Package.prototype.install = function () {
if (err) return this.emit('error', err);
rimraf(this.localPath, function (err) {
if (err) return this.emit('error', err);
return fs.rename(this.path, this.localPath, function () {
if (this.gitUrl) this.json.repository = { type: "git", url: this.gitUrl };
if (this.assetUrl) this.json = this.generateAssetJSON();
fs.writeFile(path.join(this.localPath, config.json), JSON.stringify(this.json, null, 2));
rimraf(path.join(this.localPath, '.git'), this.emit.bind(this, 'install'));
return fs.rename(this.path, this.localPath, function (err) {
if(err && err.code === 'EXDEV'){
var reader = fstream.Reader(this.path).pipe(
fstream.Writer({
type: 'Directory',
path: this.localPath
})
);
reader.on('error', this.emit.bind(this, 'error'));
reader.on('end', this.cleanUpLocal.bind(this));
return;
}
this.cleanUpLocal();
}.bind(this));
}.bind(this));
}.bind(this));
};
Package.prototype.cleanUpLocal = function () {
if (this.gitUrl) this.json.repository = { type: "git", url: this.gitUrl };
if (this.assetUrl) this.json = this.generateAssetJSON();
fs.writeFile(path.join(this.localPath, config.json), JSON.stringify(this.json, null, 2));
rimraf(path.join(this.localPath, '.git'), this.emit.bind(this, 'install'));
};
Package.prototype.generateAssetJSON = function () {
var semverParser = new RegExp('(' + semver.expressions.parse.toString().replace(/\$?\/\^?/g, '') + ')');
return {