fs.exists is deprecated, switch to fs.access

This commit is contained in:
jomo 2016-02-14 20:17:09 +01:00
parent 22ecc6f8aa
commit 3620a63d14
2 changed files with 18 additions and 17 deletions

View File

@ -40,8 +40,8 @@ function store_skin(rid, userId, profile, cache_details, callback) {
var facepath = path.join(config.directories.faces, skin_hash + ".png"); var facepath = path.join(config.directories.faces, skin_hash + ".png");
var helmpath = path.join(config.directories.helms, skin_hash + ".png"); var helmpath = path.join(config.directories.helms, skin_hash + ".png");
var skinpath = path.join(config.directories.skins, skin_hash + ".png"); var skinpath = path.join(config.directories.skins, skin_hash + ".png");
fs.exists(facepath, function(exists) { fs.access(facepath, function(fs_err) {
if (exists) { if (!fs_err) {
logging.debug(rid, "skin already exists, not downloading"); logging.debug(rid, "skin already exists, not downloading");
callback(null, skin_hash, slim); callback(null, skin_hash, slim);
} else { } else {
@ -93,8 +93,8 @@ function store_cape(rid, userId, profile, cache_details, callback) {
} else { } else {
logging.debug(rid, "new cape hash:", cape_hash); logging.debug(rid, "new cape hash:", cape_hash);
var capepath = path.join(config.directories.capes, cape_hash + ".png"); var capepath = path.join(config.directories.capes, cape_hash + ".png");
fs.exists(capepath, function(exists) { fs.access(capepath, function(fs_err) {
if (exists) { if (!fs_err) {
logging.debug(rid, "cape already exists, not downloading"); logging.debug(rid, "cape already exists, not downloading");
callback(null, cape_hash); callback(null, cape_hash);
} else { } else {
@ -272,15 +272,16 @@ exp.get_avatar = function(rid, userId, overlay, size, callback) {
var facepath = path.join(config.directories.faces, skin_hash + ".png"); var facepath = path.join(config.directories.faces, skin_hash + ".png");
var helmpath = path.join(config.directories.helms, skin_hash + ".png"); var helmpath = path.join(config.directories.helms, skin_hash + ".png");
var filepath = facepath; var filepath = facepath;
fs.exists(helmpath, function(exists) { fs.access(helmpath, function(fs_err) {
if (overlay && exists) { if (overlay && !fs_err) {
filepath = helmpath; filepath = helmpath;
} }
skins.resize_img(filepath, size, function(img_err, image) { skins.resize_img(filepath, size, function(img_err, image) {
if (img_err) { if (img_err) {
callback(img_err, -1, null, skin_hash); callback(img_err, -1, null, skin_hash);
} else { } else {
callback(err, (err ? -1 : status), image, skin_hash); status = err ? -1 : status;
callback(err, status, image, skin_hash);
} }
}); });
}); });
@ -297,8 +298,8 @@ exp.get_skin = function(rid, userId, callback) {
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash, slim) { exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash, slim) {
if (skin_hash) { if (skin_hash) {
var skinpath = path.join(config.directories.skins, skin_hash + ".png"); var skinpath = path.join(config.directories.skins, skin_hash + ".png");
fs.exists(skinpath, function(exists) { fs.access(skinpath, function(fs_err) {
if (exists) { if (!fs_err) {
logging.debug(rid, "skin already exists, not downloading"); logging.debug(rid, "skin already exists, not downloading");
skins.open_skin(rid, skinpath, function(skin_err, img) { skins.open_skin(rid, skinpath, function(skin_err, img) {
callback(skin_err || err, skin_hash, status, img, slim); callback(skin_err || err, skin_hash, status, img, slim);
@ -332,8 +333,8 @@ exp.get_render = function(rid, userId, scale, overlay, body, callback) {
return; return;
} }
var renderpath = path.join(config.directories.renders, [skin_hash, scale, get_type(overlay, body), slim ? "s" : "t"].join("-") + ".png"); var renderpath = path.join(config.directories.renders, [skin_hash, scale, get_type(overlay, body), slim ? "s" : "t"].join("-") + ".png");
fs.exists(renderpath, function(exists) { fs.access(renderpath, function(fs_err) {
if (exists) { if (!fs_err) {
renders.open_render(rid, renderpath, function(render_err, rendered_img) { renders.open_render(rid, renderpath, function(render_err, rendered_img) {
callback(render_err, 1, skin_hash, rendered_img); callback(render_err, 1, skin_hash, rendered_img);
}); });
@ -349,8 +350,8 @@ exp.get_render = function(rid, userId, scale, overlay, body, callback) {
} else if (!drawn_img) { } else if (!drawn_img) {
callback(null, 0, skin_hash, null); callback(null, 0, skin_hash, null);
} else { } else {
fs.writeFile(renderpath, drawn_img, "binary", function(fs_err) { fs.writeFile(renderpath, drawn_img, "binary", function(write_err) {
callback(fs_err, 2, skin_hash, drawn_img); callback(write_err, 2, skin_hash, drawn_img);
}); });
} }
}); });
@ -368,8 +369,8 @@ exp.get_cape = function(rid, userId, callback) {
return; return;
} }
var capepath = path.join(config.directories.capes, cape_hash + ".png"); var capepath = path.join(config.directories.capes, cape_hash + ".png");
fs.exists(capepath, function(exists) { fs.access(capepath, function(fs_err) {
if (exists) { if (!fs_err) {
logging.debug(rid, "cape already exists, not downloading"); logging.debug(rid, "cape already exists, not downloading");
skins.open_skin(rid, capepath, function(skin_err, img) { skins.open_skin(rid, capepath, function(skin_err, img) {
callback(skin_err || err, cape_hash, status, img); callback(skin_err || err, cape_hash, status, img);

View File

@ -22,8 +22,8 @@ var routes = {
// serves assets from lib/public // serves assets from lib/public
function asset_request(req, callback) { function asset_request(req, callback) {
var filename = path.join(__dirname, "public", req.url.path_list.join("/")); var filename = path.join(__dirname, "public", req.url.path_list.join("/"));
fs.exists(filename, function(exists) { fs.access(filename, function(fs_err) {
if (exists) { if (!fs_err) {
fs.readFile(filename, function(err, data) { fs.readFile(filename, function(err, data) {
callback({ callback({
body: data, body: data,