Skip to content

Commit

Permalink
fix: improve checking file permission
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pastak committed Jun 6, 2019
1 parent 6b50c96 commit de41351
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

This comment has been minimized.

Copy link
@rseeberg

rseeberg Jun 17, 2019

This breaks my builds on windows, since process.getuid() is not available on windows

https://nodejs.org/api/process.html#process_process_getuid

This function is only available on POSIX platforms (i.e. not Windows or Android).

This comment has been minimized.

Copy link
@evenstensberg

evenstensberg Jun 18, 2019

Member

Thank you for pointing that out!

});
}
}
Expand Down

0 comments on commit de41351

Please sign in to comment.