Remove cache directory before downloading

This ensures any previously failed downloads/extractions are cleaned
up before a new atom-shell distribution is downloaded and extracted.
This commit is contained in:
Kevin Sawicki 2013-09-05 21:24:02 -07:00
parent a7eaac3984
commit fe4f9471e6

View File

@ -26,10 +26,12 @@ module.exports = (grunt) ->
inputStream.on 'response', (response) ->
if response.statusCode is 200
grunt.log.writeln("Downloading atom-shell version #{version.cyan}")
cachePath = "#{getCachePath(version)}/atom-shell.zip"
mkdir(path.dirname(cachePath))
outputStream = fs.createWriteStream(cachePath)
outputStream.on 'close', -> callback(null, cachePath)
cacheDirectory = getCachePath(version)
rm(cacheDirectory)
mkdir(cacheDirectory)
cacheFile = path.join(cacheDirectory, 'atom-shell.zip')
outputStream = fs.createWriteStream(cacheFile)
outputStream.on 'close', -> callback(null, cacheFile)
inputStream.pipe(outputStream)
else
if response.statusCode is 404
@ -45,7 +47,7 @@ module.exports = (grunt) ->
try
zip = new AdmZip(zipPath);
zip.extractAllTo(directoryPath, true)
rm(zipPath, force: true)
rm(zipPath)
callback()
catch error
callback(error)