Skip to content

Commit de41351

Browse files
committed
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

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎bin/cli.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,17 @@ For more information, see https://webpack.js.org/api/cli/.`);
342342
constnow=newDate();
343343
if(now.getDay()===MONDAY){
344344
const{ access, constants, statSync, utimesSync }=require("fs");
345-
constlastPrint=statSync(openCollectivePath).atime;
345+
conststat=statSync(openCollectivePath);
346+
constlastPrint=stat.atime;
347+
constfileOwnerId=stat.uid;
346348
constlastPrintTS=newDate(lastPrint).getTime();
347349
consttimeSinceLastPrint=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);
353356
});
354357
}
355358
}

0 commit comments

Comments
 (0)