@@ -389,6 +389,16 @@ TString TEnvRec::ExpandValue(const char *value)
389389 return val;
390390}
391391
392+ // //////////////////////////////////////////////////////////////////////////////
393+ // / Returns the home directory or, if set, the value of the environment variable
394+ // / ROOTENV_USER_PATH.
395+ const char *TEnv::GetUserDirectory () const
396+ {
397+ const auto customPath = gSystem ->Getenv (" ROOTENV_USER_PATH" );
398+ if (customPath)
399+ return customPath;
400+ return gSystem ->HomeDirectory ();
401+ }
392402
393403// //////////////////////////////////////////////////////////////////////////////
394404// / Create a resource table and read the (possibly) three resource files,
@@ -422,16 +432,10 @@ TEnv::TEnv(const char *name)
422432 const char *s = gSystem ->PrependPathName (TROOT::GetEtcDir (), sname);
423433 ReadFile (s, kEnvGlobal );
424434 if (!gSystem ->Getenv (" ROOTENV_NO_HOME" )) {
425- if (const auto rootrcPath = gSystem ->Getenv (" ROOTENV_USER_PATH" )) {
426- TString temp (name);
427- const char *s1 = gSystem ->PrependPathName (rootrcPath, temp);
428- ReadFile (s1, kEnvUser );
429- } else {
430- TString temp (name);
431- const char *s1 = gSystem ->PrependPathName (gSystem ->HomeDirectory (), temp);
432- ReadFile (s1, kEnvUser );
433- }
434- if (strcmp (gSystem ->HomeDirectory (), gSystem ->WorkingDirectory ())) {
435+ TString temp (name);
436+ gSystem ->PrependPathName (GetUserDirectory (), temp);
437+ ReadFile (temp.Data (), kEnvUser );
438+ if (strcmp (GetUserDirectory (), gSystem ->WorkingDirectory ())) {
435439 ReadFile (name, kEnvLocal );
436440 }
437441 } else {
@@ -693,16 +697,16 @@ void TEnv::SaveLevel(EEnvLevel level)
693697 FILE *ifp, *ofp;
694698
695699 if (level == kEnvGlobal ) {
696-
697700 TString sname = " system" ;
698701 sname += fRcName ;
699702 rootrcdir = gSystem ->PrependPathName (TROOT::GetEtcDir (), sname);
700703 } else if (level == kEnvUser ) {
701- rootrcdir = gSystem ->PrependPathName (gSystem -> HomeDirectory (), fRcName );
702- } else if (level == kEnvLocal )
704+ rootrcdir = gSystem ->PrependPathName (GetUserDirectory (), fRcName );
705+ } else if (level == kEnvLocal ) {
703706 rootrcdir = fRcName ;
704- else
707+ } else {
705708 return ;
709+ }
706710
707711 if ((ofp = fopen (TString::Format (" %s.new" , rootrcdir.Data ()).Data (), " w" ))) {
708712 ifp = fopen (rootrcdir.Data (), " r" );
0 commit comments