Skip to content

Commit de41351

Browse files
committedJun 6, 2019
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.
1 parent 6b50c96 commit de41351

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎bin/cli.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,17 @@ For more information, see https://webpack.js.org/api/cli/.`);
342342
const now = new Date();
343343
if (now.getDay() === MONDAY) {
344344
const { access, constants, statSync, utimesSync } = require("fs");
345-
const lastPrint = statSync(openCollectivePath).atime;
345+
const stat = statSync(openCollectivePath);
346+
const lastPrint = stat.atime;
347+
const fileOwnerId = stat.uid;
346348
const lastPrintTS = new Date(lastPrint).getTime();
347349
const timeSinceLastPrint = now.getTime() - lastPrintTS;
348350
if (timeSinceLastPrint > SIX_DAYS) {
349351
require(openCollectivePath);
350352
// On windows we need to manually update the atime
353+
// Updating utime requires process owner is as same as file owner
351354
access(openCollectivePath, constants.W_OK, e => {
352-
if (!e) utimesSync(openCollectivePath, now, now);
355+
if (!e && fileOwnerId === process.getuid()) utimesSync(openCollectivePath, now, now);
Has conversations. Original line has conversations.
353356
});
354357
}
355358
}

0 commit comments

Comments
 (0)
Please sign in to comment.