Commit 1515c21c authored by priit's avatar priit
Browse files

Utiliidi töö katkestamine

parent 40360d25
...@@ -41,21 +41,32 @@ function ArchiveExtractor() { ...@@ -41,21 +41,32 @@ function ArchiveExtractor() {
logger.debug('Extracting *.zip file'); logger.debug('Extracting *.zip file');
var checkForCallback = function () {
if (count == 0) {
session.message = Session.messages.OK;
return callback(null, session);
}
};
fs.createReadStream(file).on('error', function(error) { fs.createReadStream(file).on('error', function(error) {
session.setErrors(error); session.setErrors(error);
return callback(error, session); return callback(error, session);
}) })
.pipe(unzip.Parse()) .pipe(unzip.Parse())
.on('entry', function(entry) { .on('entry', function(entry) {
var savePath = SessionService.getStorePath(session.id);
var isFile = ('File' == entry.type); var isFile = ('File' == entry.type);
var fullpath = path.join(savePath, entry.path);
//logger.debug('Fullpath: ' + fullpath);
var directory = (isFile ? path.dirname(fullpath) : fullpath);
if (isFile) { if (isFile) {
count++; count++;
} }
var savePath = SessionService.getStorePath(session.id);
var fullpath = path.join(savePath, entry.path);
logger.debug('Fullpath: ' + fullpath);
var directory = (isFile ? path.dirname(fullpath) : fullpath);
logger.debug('Countx: ' + count); logger.debug('Countx: ' + count);
mkdirp(directory, function(err) { mkdirp(directory, function(err) {
...@@ -77,10 +88,7 @@ function ArchiveExtractor() { ...@@ -77,10 +88,7 @@ function ArchiveExtractor() {
contentType: mime.lookup(fullpath) // getting the original file mime type contentType: mime.lookup(fullpath) // getting the original file mime type
}); });
count--; count--;
//logger.debug('Countx: ' + count); checkForCallback();
if (count == 0) {
session.message = Session.messages.OK;
}
}); });
} else { } else {
entry.autodrain(); entry.autodrain();
...@@ -89,11 +97,7 @@ function ArchiveExtractor() { ...@@ -89,11 +97,7 @@ function ArchiveExtractor() {
}) })
.on('close', function() { .on('close', function() {
logger.debug('Close count: ' + count); logger.debug('Close count: ' + count);
checkForCallback();
if (count == 0) {
session.message = Session.messages.OK;
}
return callback(null, session);
}); });
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment