[Bf-blender-cvs] [9d152263837] master: Ghost/Linux: Avoid error print if special directory can't be determined

Julian Eisel noreply at git.blender.org
Wed Dec 16 20:37:07 CET 2020


Commit: 9d152263837f0ac5e790e0b12d3b3cfed31bed0f
Author: Julian Eisel
Date:   Wed Dec 16 20:28:15 2020 +0100
Branches: master
https://developer.blender.org/rB9d152263837f0ac5e790e0b12d3b3cfed31bed0f

Ghost/Linux: Avoid error print if special directory can't be determined

The function is supposed to fail gracefully if there is some error. That
includes not being able to find `xdg-user-dir`. So don't let the error
be printed to the console, it's misleading/annoying.
>From what I can tell we'll detect that problem fine and return NULL
then.

===================================================================

M	intern/ghost/intern/GHOST_SystemPathsUnix.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemPathsUnix.cpp b/intern/ghost/intern/GHOST_SystemPathsUnix.cpp
index fdfde13b915..86f3a0a31fb 100644
--- a/intern/ghost/intern/GHOST_SystemPathsUnix.cpp
+++ b/intern/ghost/intern/GHOST_SystemPathsUnix.cpp
@@ -142,7 +142,8 @@ const GHOST_TUns8 *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDi
   }
 
   static string path = "";
-  string command = string("xdg-user-dir ") + type_str;
+  /* Pipe stderr to /dev/null to avoid error prints. We will fail gracefully still. */
+  string command = string("xdg-user-dir ") + type_str + " 2> /dev/null";
 
   FILE *fstream = popen(command.c_str(), "r");
   if (fstream == NULL) {
@@ -163,7 +164,7 @@ const GHOST_TUns8 *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDi
   }
 
   path = path_stream.str();
-  return (const GHOST_TUns8 *)path.c_str();
+  return path[0] ? (const GHOST_TUns8 *)path.c_str() : NULL;
 }
 
 const GHOST_TUns8 *GHOST_SystemPathsUnix::getBinaryDir() const



More information about the Bf-blender-cvs mailing list