@@ -6,7 +6,7 @@ module.exports = (helpers, config) => {
66    const  npmPrefixPathSuffixes  =  [ "/lib/node_modules" ,  "/lib/bin" ,  "/lib/share" ] ; 
77
88    const  {  logMessage,  execSync,  sudoExec,  stringFormat }  =  helpers ; 
9-     const  {  getPrefixPathCommand,  getCachePathCommand,  fixNPMPermissionsCommand }  =  config ; 
9+     const  {  getPrefixPathCommand,  getCachePathCommand,  getCurrentUserCommand ,   fixNPMPermissionsCommand }  =  config ; 
1010
1111    const  getNPMFoldersWithMissingPermissions  =  ( stderr )  =>  { 
1212        if  ( _ . isEmpty ( getPrefixPathCommand )  ||  _ . isEmpty ( getCachePathCommand )  ||  ! eaccessCodeString . test ( stderr ) )  { 
@@ -47,6 +47,24 @@ module.exports = (helpers, config) => {
4747        return  folders ; 
4848    } ; 
4949
50+     const  getCurrentUser  =  ( )  =>  { 
51+         if  ( _ . isEmpty ( getCurrentUserCommand ) )  { 
52+             return  "" ; 
53+         } 
54+ 
55+         let  currentUser  =  "" ; 
56+ 
57+         try  { 
58+             currentUser  =  execSync ( getCurrentUserCommand ) ; 
59+         }  catch  ( error )  { 
60+             logMessage ( `Get current user failed. Error:\n${ error }  ` ) ; 
61+ 
62+             currentUser  =  "" ; 
63+         } 
64+ 
65+         return  currentUser ; 
66+     } ; 
67+ 
5068    const  fixMissingNPMPermissions  =  ( folderPaths )  =>  { 
5169        if  ( _ . isEmpty ( folderPaths ) )  { 
5270            logMessage ( "No folders with incorrect permissions." ) ; 
@@ -60,11 +78,19 @@ module.exports = (helpers, config) => {
6078            return  Promise . resolve ( ) ; 
6179        } 
6280
81+         const  currentUser  =  getCurrentUser ( ) ; 
82+ 
83+         if  ( _ . isEmpty ( currentUser ) )  { 
84+             logMessage ( "No current user." ) ; 
85+ 
86+             return  Promise . resolve ( ) ; 
87+         } 
88+ 
6389        const  folderExpression  =  _ . chain ( folderPaths ) 
6490            . map ( folderPath  =>  `'${ folderPath }  '` ) 
6591            . join ( " " ) 
6692            . value ( ) ; 
67-         const  command  =  stringFormat ( fixNPMPermissionsCommand ,  folderExpression ) ; 
93+         const  command  =  stringFormat ( fixNPMPermissionsCommand ,  currentUser ,   folderExpression ) ; 
6894
6995        return  sudoExec ( command ) ; 
7096    } ; 
0 commit comments