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 {