diff options
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/fs.js | 7 | ||||
-rw-r--r-- | lib/utils/git.js | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/utils/fs.js b/lib/utils/fs.js index c0ff0c9..840d1f9 100644 --- a/lib/utils/fs.js +++ b/lib/utils/fs.js @@ -61,6 +61,12 @@ function genTmpFile(opts) { .get(0); } +// Generate temporary dir +function genTmpDir(opts) { + return Promise.nfcall(tmp.dir, opts) + .get(0); +} + // Download an image function download(uri, dest) { return writeStream(dest, request(uri)); @@ -101,6 +107,7 @@ module.exports = { writeStream: writeStream, copy: copyFile, tmpFile: genTmpFile, + tmpDir: genTmpDir, download: download, uniqueFilename: uniqueFilename, ensure: ensureFile diff --git a/lib/utils/git.js b/lib/utils/git.js index baf0fab..fc75ee3 100644 --- a/lib/utils/git.js +++ b/lib/utils/git.js @@ -6,11 +6,12 @@ var URI = require('urijs'); var pathUtil = require('./path'); var Promise = require('./promise'); var command = require('./command'); +var fs = require('./fs'); var GIT_PREFIX = 'git+'; function Git(tmpDir) { - this.tmpDir = tmpDir; + this.tmpDir; this.cloned = {}; } @@ -19,11 +20,23 @@ Git.prototype.repoID = function(host, ref) { return crc.crc32(host+'#'+(ref || '')).toString(16); }; +// Allocate a temporary folder for cloning repos in it +Git.prototype.allocateDir = function() { + var that = this; + + if (this.tmpDir) return Promise(); + + return fs.tmpDir() + .then(function(dir) { + that.tmpDir = dir; + }); +}; + // Clone a git repository if non existant Git.prototype.clone = function(host, ref) { var that = this; - return Promise() + return this.allocateDir() // Return or clone the git repo .then(function() { |