From 600e7002c9acc59ba21c49e0f1b7e91718d5370f Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 19 Mar 2019 00:24:42 -0400 Subject: [PATCH] really fix cross-filesystem rename by using mv instead --- webapp/CHANGELOG.md | 10 ++++ webapp/README.md | 2 +- webapp/package-lock.json | 102 +++++++++++++++++++++++++++++++++++++++ webapp/package.json | 1 + webapp/server.js | 11 ++++- 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 webapp/CHANGELOG.md diff --git a/webapp/CHANGELOG.md b/webapp/CHANGELOG.md new file mode 100644 index 0000000..c0d016f --- /dev/null +++ b/webapp/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), + +## [git] - 2019-03-19 +### Added +- skin uploading via webapp (chooses Bucket_Game, or ENLIVEN if present) +- `npm install formidable mv` (switched from fs.rename to mv due to + rename not working across filesystems (tmp is commonly on a different + volume). diff --git a/webapp/README.md b/webapp/README.md index c9e38d0..ec58302 100755 --- a/webapp/README.md +++ b/webapp/README.md @@ -63,7 +63,7 @@ fi cd "$target_dir" npm init #except changed jade to pug -npm install express static-favicon morgan cookie-parser body-parser debug pug passport passport-local mongoose formidable +npm install express static-favicon morgan cookie-parser body-parser debug pug passport passport-local mongoose formidable mv #NOTE: multiparty has streaming like busboy, but is non-trivial to implement ``` diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 9e7fd13..b13276f 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -18,6 +18,11 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, "body-parser": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", @@ -35,11 +40,25 @@ "type-is": "~1.6.15" } }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, "bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, "content-disposition": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", @@ -173,6 +192,18 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "glob": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", + "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", + "requires": { + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "2 || 3", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "http-errors": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", @@ -189,6 +220,15 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", @@ -232,16 +272,52 @@ "mime-db": "~1.33.0" } }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + } + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "mv": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/mv/-/mv-2.1.1.tgz", + "integrity": "sha1-rmzg1vbV4KT32JN5jQPB6pVZtqI=", + "requires": { + "mkdirp": "~0.5.1", + "ncp": "~2.0.0", + "rimraf": "~2.4.0" + } + }, "n-readlines": { "version": "0.2.8", "resolved": "https://registry.npmjs.org/n-readlines/-/n-readlines-0.2.8.tgz", "integrity": "sha512-FRr6GU0vooiPAuHMBt/Pspm4htItJKCehs8Q2urdUuigXsdQzP8V03UaQedeCmiygqJwtuGhnidWHRHhUOAg9w==" }, + "ncp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", + "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=" + }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", @@ -255,11 +331,24 @@ "ee-first": "1.1.1" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, "parseurl": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", @@ -318,6 +407,14 @@ } } }, + "rimraf": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.4.5.tgz", + "integrity": "sha1-7nEM5dk6j9uFb7Xqj/Di11k0sto=", + "requires": { + "glob": "^6.0.1" + } + }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", @@ -387,6 +484,11 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } } diff --git a/webapp/package.json b/webapp/package.json index baa1064..f3743aa 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -15,6 +15,7 @@ "cookie-parser": "^1.4.3", "express": "^4.7.2", "formidable": "^1.2.1", + "mv": "^2.1.1", "n-readlines": "^0.2.8" } } diff --git a/webapp/server.js b/webapp/server.js index 0f38bc9..1432dda 100644 --- a/webapp/server.js +++ b/webapp/server.js @@ -25,6 +25,7 @@ var express = require('express'), const os = require('os'); var formidable = require('formidable') var querystring = require("querystring"); // built-in +var mv = require('mv'); // var util = require('util') var app = express(); @@ -56,7 +57,10 @@ var unique_flags = [ //#endregion derived from mtsenliven.py function regeneratePaths() { - skinDir = minetestPath + "/games/ENLIVEN/mods/codercore/coderskins/textures"; + skinDir = minetestPath + "/games/Bucket_Game/mods/codercore/coderskins/textures"; + if (fs.existsSync( minetestPath + "/games/ENLIVEN")) { + skinDir = minetestPath + "/games/ENLIVEN/mods/codercore/coderskins/textures"; + } console.log("skinDir: \"" + skinDir + "\""); } @@ -354,11 +358,14 @@ app.post('/set-skin', function (req, res){ var originalPath = files.userFile.path; console.log("trying to rename " + files.userFile.path + " to " + directPath); - fs.rename(files.userFile.path, directPath, function(err) { + // NOTE: rename does not work if tmp is on different device (common) + mv(files.userFile.path, directPath, function(err) { + // fs.rename(files.userFile.path, directPath, function(err) { if (err) { msg = "Failed to rename " + originalPath + " to " + directPath; console.log(msg); + console.log(JSON.stringify(err)); msg += "
\n"; //next(err); // TODO: why does next above show: