Skip to content

Commit 44087de

Browse files
committed
increasing counter for each file before the end event fired
1 parent 499475e commit 44087de

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/uploadhandler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,23 @@ module.exports = function (options) {
100100
}
101101
})
102102
.on('file', function (name, file) {
103+
counter++;
103104
var fileInfo = map[path.basename(file.path)];
104105
fs.exists(file.path, function(exists) {
105106
if (exists) {
106107
fileInfo.size = file.size;
107108
if (!fileInfo.validate()) {
108109
fs.unlink(file.path);
110+
counter--;
109111
return;
110112
}
111113

112114
var generatePreviews = function () {
113115
if (options.imageTypes.test(fileInfo.name)) {
114116
_.each(options.imageVersions, function (value, version) {
117+
counter++;
115118
// creating directory recursive
116119
mkdirp(options.uploadDir() + '/' + version + '/', function (err, made) {
117-
counter++;
118120
var opts = options.imageVersions[version];
119121
imageMagick.resize({
120122
width: opts.width,
@@ -129,7 +131,6 @@ module.exports = function (options) {
129131
}
130132

131133
mkdirp(options.uploadDir() + '/', function(err, made) {
132-
counter++;
133134
fs.rename(file.path, options.uploadDir() + '/' + fileInfo.name, function (err) {
134135
if (!err) {
135136
generatePreviews();
@@ -149,6 +150,7 @@ module.exports = function (options) {
149150
});
150151
});
151152
}
153+
else counter--;
152154
});
153155
})
154156
.on('aborted', function () {

0 commit comments

Comments
 (0)