Parcourir la source

FIX: add new jfile "queryTempfilePath" function

Adding common function to be used to query the location for temp files

Signed-off-by: William Whitehead <william.whitehead@lexisnexis.com>
William Whitehead il y a 13 ans
Parent
commit
223274c345
2 fichiers modifiés avec 26 ajouts et 0 suppressions
  1. 25 0
      system/jlib/jutil.cpp
  2. 1 0
      system/jlib/jutil.hpp

+ 25 - 0
system/jlib/jutil.cpp

@@ -2554,6 +2554,31 @@ int parseCommandLine(const char * cmdline, MemoryBuffer &mb, const char** &argvo
     return 0;
 }
 
+jlib_decl StringBuffer &getTempFilePath(StringBuffer & target, const char * component, IPropertyTree * pTree)
+{
+    StringBuffer dir;
+    if (pTree)
+        getConfigurationDirectory(pTree->queryPropTree("Directories"),"temp",component,pTree->queryProp("@name"),dir);
+    if (!dir.length())
+    {
+#ifdef _WIN32
+        char path[_MAX_PATH+1];
+        if(GetTempPath(sizeof(path),path))
+            dir.append(path).append("HPCCSystems\\hpcc-data");
+        else
+            dir.append("c:\\HPCCSystems\\hpcc-data\\temp");
+#else
+        dir.append(getenv("TMPDIR"));
+        if (!dir.length())
+            dir.append("/var/lib");
+        dir.append("/HPCCSystems/hpcc-data/temp");
+#endif
+    }
+    dir.append(PATHSEPCHAR).append(component);
+    recursiveCreateDirectory(dir.str());
+    return target.set(dir);
+}
+
 //#define TESTURL
 #ifdef TESTURL
 

+ 1 - 0
system/jlib/jutil.hpp

@@ -269,6 +269,7 @@ extern jlib_decl int parseCommandLine(const char * cmdline, MemoryBuffer &mb, co
 
 extern jlib_decl bool safe_ecvt(size_t len, char * buffer, double value, int numDigits, int * decimal, int * sign);
 extern jlib_decl bool safe_fcvt(size_t len, char * buffer, double value, int numPlaces, int * decimal, int * sign);
+extern jlib_decl StringBuffer &getTempFilePath(StringBuffer & target, const char * component, IPropertyTree * pTree);
 
 #endif