check and log all fs.unlink errors

v1.18.x
barisusakli 10 years ago
parent 31fef4f429
commit cf193581e4

@ -3,6 +3,7 @@
var fs = require('fs'),
path = require('path'),
nconf = require('nconf'),
winston = require('winston'),
file = require('../../file'),
plugins = require('../../plugins');
@ -17,7 +18,11 @@ uploadsController.uploadCategoryPicture = function(req, res, next) {
try {
params = JSON.parse(req.body.params);
} catch (e) {
fs.unlink(uploadedFile.path);
fs.unlink(uploadedFile.path, function(err) {
if (err) {
winston.error(err);
}
});
return next(e);
}
@ -33,7 +38,11 @@ uploadsController.uploadFavicon = function(req, res, next) {
if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
file.saveFileToLocal('favicon.ico', 'system', uploadedFile.path, function(err, image) {
fs.unlink(uploadedFile.path);
fs.unlink(uploadedFile.path, function(err) {
if (err) {
winston.error(err);
}
});
if (err) {
return next(err);
}
@ -62,7 +71,11 @@ function upload(name, req, res, next) {
function validateUpload(req, res, next, uploadedFile, allowedTypes) {
if (allowedTypes.indexOf(uploadedFile.type) === -1) {
fs.unlink(uploadedFile.path);
fs.unlink(uploadedFile.path, function(err) {
if (err) {
winston.error(err);
}
});
res.json({error: '[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]'});
return false;
@ -73,7 +86,11 @@ function validateUpload(req, res, next, uploadedFile, allowedTypes) {
function uploadImage(filename, folder, uploadedFile, req, res, next) {
function done(err, image) {
fs.unlink(uploadedFile.path);
fs.unlink(uploadedFile.path, function(err) {
if (err) {
winston.error(err);
}
});
if (err) {
return next(err);
}

@ -136,9 +136,14 @@ function uploadFile(uid, uploadedFile, callback) {
}
function deleteTempFiles(files) {
for(var i=0; i<files.length; ++i) {
fs.unlink(files[i].path);
}
async.each(files, function(file, next) {
fs.unlink(file.path, function(err) {
if (err) {
winston.error(err);
}
next();
});
});
}

@ -101,7 +101,11 @@ module.exports = function(User) {
}
User.uploadPicture(uid, downloadedImage, function(err, image) {
fs.unlink(filename);
fs.unlink(filename, function(err) {
if (err) {
winston.error(err);
}
});
callback(err, image);
});
});

Loading…
Cancel
Save