From 10b0f8c379860f868dffa75762a4c8f75c32c716 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Tue, 14 Jul 2020 07:02:46 +0100 Subject: [PATCH] fix: create app failing from unknown folder copy issues --- .../server/src/api/controllers/application.js | 6 ++++++ .../pages/unauthenticated/screens/placeholder | 0 packages/server/src/utilities/chmodr.js | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/screens/placeholder create mode 100644 packages/server/src/utilities/chmodr.js diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index eaa5b07be7..0b68b0b080 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -11,6 +11,7 @@ const { exec } = require("child_process") const sqrl = require("squirrelly") const setBuilderToken = require("../../utilities/builder/setBuilderToken") const fs = require("fs-extra") +const chmodr = require("../../utilities/chmodr") exports.fetch = async function(ctx) { const db = new CouchDB(ClientDb.name(getClientId(ctx))) @@ -138,6 +139,11 @@ const createEmptyAppPackage = async (ctx, app) => { await copy(templateFolder, newAppFolder) + // this line allows full permission on copied files + // we have an unknown problem without this, whereby the + // files get weird permissions and cant be written to :( + await chmodr(newAppFolder, 0o777) + await updateJsonFile(join(appsFolder, app._id, "package.json"), { name: npmFriendlyAppName(app.name), }) diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/screens/placeholder b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/screens/placeholder new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/server/src/utilities/chmodr.js b/packages/server/src/utilities/chmodr.js new file mode 100644 index 0000000000..b5adc756f6 --- /dev/null +++ b/packages/server/src/utilities/chmodr.js @@ -0,0 +1,17 @@ +const fs = require("fs-extra") +const { join } = require("path") + +const chmodr = async (dir, perms) => { + const children = await fs.readdir(dir) + for (let child of children) { + const fullChildPath = join(dir, child) + const stat = await fs.stat(join(dir, child)) + if (stat.isFile()) { + await fs.chmod(fullChildPath, perms) + } else { + await chmodr(fullChildPath, perms) + } + } +} + +module.exports = chmodr