← Back to team overview

kicad-developers team mailing list archive

Re: KICAD_CACHE_HOME environment variable

 

On 08.05.2018 02:57, Mike Wodarczyk wrote:
Attached is a patch to use a new KICAD_CACHE_HOME environment variable to set a custom path for the lockfiles on all platforms. It's tested under Windows and works as expected.

Oops attached the wrong file. This is the compiling patch. Sorry for the inconvience :-)

From 3d05a27d00453c608031efec702ca8f898e0a584 Mon Sep 17 00:00:00 2001
From: mwayne <wodarczykmike@xxxxxxxxx>
Date: Wed, 9 May 2018 02:27:25 +0200
Subject: [PATCH] Make lockfile path adjustable.

Use KICAD_CACHE_HOME environment variable on all platforms so users can specify a custom cache path.
---
 common/lockfile.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/common/lockfile.cpp b/common/lockfile.cpp
index 92ee0bd..2df4475 100644
--- a/common/lockfile.cpp
+++ b/common/lockfile.cpp
@@ -61,13 +61,13 @@ wxString GetKicadLockFilePath()
     wxFileName lockpath;
     lockpath.AssignDir( wxGetHomeDir() ); // Default wx behavior
 
+    wxString envstr;
 #if defined( __WXMAC__ )
     // In OSX use the standard per user cache directory
     lockpath.AppendDir( "Library" );
     lockpath.AppendDir( "Caches" );
     lockpath.AppendDir( "kicad" );
 #elif defined( __UNIX__ )
-    wxString envstr;
     // Try first the standard XDG_RUNTIME_DIR, falling back to XDG_CACHE_HOME
     if( wxGetEnv( "XDG_RUNTIME_DIR", &envstr ) && !envstr.IsEmpty() )
     {
@@ -86,12 +86,18 @@ wxString GetKicadLockFilePath()
     lockpath.AppendDir( "kicad" );
 #endif
 
-#if defined( __WXMAC__ ) || defined( __UNIX__ )
+    // Use KICAD_CACHE_HOME to allow the user to force a specific cache path.
+    if( wxGetEnv( wxT( "KICAD_CACHE_HOME" ), &envstr ) && !envstr.IsEmpty() )
+    {
+        // Override the assignment above with KICAD_CACHE_HOME
+        lockpath.AssignDir( envstr );
+    }
+
     if( !lockpath.DirExists() )
     {
         // Lockfiles should be only readable by the user
         lockpath.Mkdir( 0700, wxPATH_MKDIR_FULL );
     }
-#endif
+
     return lockpath.GetPath();
 }
-- 
2.7.2.windows.1


Follow ups

References