changeset 206:04c2a895b679

RLGWebD: replace deprecated fs.exists() with fs.access().
author John "Elwin" Edwards
date Fri, 27 Jan 2017 15:43:10 -0500
parents 6651f54a0062
children ffe22d88bea1
files rlgwebd
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rlgwebd	Thu Jan 12 19:02:20 2017 -0500
+++ b/rlgwebd	Fri Jan 27 15:43:10 2017 -0500
@@ -486,8 +486,11 @@
   var savedirc = game.uname + "save";
   var basename = String(pwent.uid) + "-" + user + game.suffix;
   var savefile = path.join("/var/games/roguelike", savedirc, basename);
-  fs.exists(savefile, function (exist) {
-    args.unshift(exist);
+  fs.access(savefile, function (err) {
+    if (err)
+      args.unshift(false);
+    else
+      args.unshift(true);
     callback.apply(null, args);
   });
 }
@@ -838,9 +841,9 @@
     path.join(nname, "index.html"); /* it was a directory */
   var realname = path.join(rlgwebd_options.static_root, nname);
   var extension = path.extname(realname);
-  fs.exists(realname, function (exists) {
+  fs.access(realname, function (access_err) {
     var resheaders = {};
-    if (!exists || !extension || extension == ".html")
+    if (access_err || !extension || extension == ".html")
       resheaders["Content-Type"] = "text/html; charset=utf-8";
     else if (extension == ".png")
       resheaders["Content-Type"] = "image/png";
@@ -852,7 +855,7 @@
       resheaders["Content-Type"] = "image/svg+xml";
     else
       resheaders["Content-Type"] = "application/octet-stream";
-    if (exists) {
+    if (!access_err) {
       fs.readFile(realname, function (error, data) {
         if (error) {
           res.writeHead(500, {});