From dbcea61300bf170c5c5b96d6736ff600199f2aaa Mon Sep 17 00:00:00 2001 From: Nathan Bleigh Date: Tue, 11 Sep 2012 17:38:12 -0500 Subject: [PATCH] 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 --- lib/core/package.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/core/package.js b/lib/core/package.js index 976f8165..75c796da 100644 --- a/lib/core/package.js +++ b/lib/core/package.js @@ -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 {