Fix handling of larger build packs and straight Dockerfiles

This commit is contained in:
Joseph Schorr 2014-05-01 01:48:39 -04:00
parent 77b9bc05ac
commit 65e6041f55
2 changed files with 40 additions and 9 deletions

View file

@ -235,6 +235,26 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
};
dataFileService.tryAsTarGz_ = function(buf, success, failure) {
var gunzip = new Zlib.Gunzip(buf);
var plain = null;
try {
plain = gunzip.decompress();
} catch (e) {
failure();
return;
}
dataFileService.arrayToString(plain, function(result) {
if (result) {
dataFileService.tryAsTarGzWithStringData_(result, success, failure);
} else {
failure();
}
});
};
dataFileService.tryAsTarGzWithStringData_ = function(strData, success, failure) {
var collapsePath = function(originalPath) {
// Tar files can contain entries of the form './', so we need to collapse
// those paths down.
@ -248,12 +268,9 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
return parts.join('/');
};
var gunzip = new Zlib.Gunzip(buf);
var plain = gunzip.decompress();
var handler = new MultiFile();
handler.files = [];
handler.processTarChunks(dataFileService.arrayToString(plain), 0);
handler.processTarChunks(strData, 0);
if (!handler.files.length) {
failure();
return;
@ -288,8 +305,19 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
reader.readAsText(blob);
};
dataFileService.arrayToString = function(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
dataFileService.arrayToString = function(buf, callback) {
var bb = new Blob([buf], {type: 'application/octet-binary'});
var f = new FileReader();
f.onload = function(e) {
callback(e.target.result);
};
f.onerror = function(e) {
callback(null);
};
f.onabort = function(e) {
callback(null);
};
f.readAsText(bb);
};
dataFileService.readDataArrayAsPossibleArchive = function(buf, success, failure) {

View file

@ -841,7 +841,7 @@ function BuildPackageCtrl($scope, Restangular, ApiService, DataFileService, $rou
if (dockerfile && dockerfile.canRead) {
DataFileService.blobToString(dockerfile.toBlob(), function(result) {
$scope.$apply(function() {
$scope.dockerFilePath = dockerfilePath;
$scope.dockerFilePath = dockerfilePath || 'Dockerfile';
$scope.dockerFileContents = result;
});
});
@ -851,8 +851,11 @@ function BuildPackageCtrl($scope, Restangular, ApiService, DataFileService, $rou
};
var notarchive = function() {
$scope.dockerFileContents = DataFileService.arrayToString(uint8array);
$scope.loaded = true;
DataFileService.arrayToString(uint8array, function(r) {
$scope.dockerFilePath = 'Dockerfile';
$scope.dockerFileContents = r;
$scope.loaded = true;
});
};
DataFileService.readDataArrayAsPossibleArchive(uint8array, archiveread, notarchive);