From de413515ed0bba4e72e24e758f6701a5c0ec0886 Mon Sep 17 00:00:00 2001 From: pastak Date: Thu, 6 Jun 2019 18:27:10 +0900 Subject: [PATCH] fix: improve checking file permission It is happen EPERM when node_modules is owned by `root` and webpack-cli is executed by user excepted `root`. It should check file and process owner. --- bin/cli.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index bed161abea6..5510c46ca01 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -342,14 +342,17 @@ For more information, see https://webpack.js.org/api/cli/.`); const now = new Date(); if (now.getDay() === MONDAY) { const { access, constants, statSync, utimesSync } = require("fs"); - const lastPrint = statSync(openCollectivePath).atime; + const stat = statSync(openCollectivePath); + const lastPrint = stat.atime; + const fileOwnerId = stat.uid; const lastPrintTS = new Date(lastPrint).getTime(); const timeSinceLastPrint = now.getTime() - lastPrintTS; if (timeSinceLastPrint > SIX_DAYS) { require(openCollectivePath); // On windows we need to manually update the atime + // Updating utime requires process owner is as same as file owner access(openCollectivePath, constants.W_OK, e => { - if (!e) utimesSync(openCollectivePath, now, now); + if (!e && fileOwnerId === process.getuid()) utimesSync(openCollectivePath, now, now); }); } }