5485fb
From 2a28dcd3f6e4af7a5b2d7d7810b26b6321dd1bf1 Mon Sep 17 00:00:00 2001
5485fb
From: Jakub Jelen <jjelen@redhat.com>
5485fb
Date: Tue, 10 Nov 2020 14:44:43 +0100
5485fb
Subject: [PATCH 1/3] ctx: Use more standard cache directory
5485fb
5485fb
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
5485fb
---
5485fb
 src/libopensc/ctx.c | 9 +++++++--
5485fb
 1 file changed, 7 insertions(+), 2 deletions(-)
5485fb
5485fb
diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c
5485fb
index 6b57170f01..d6058c070e 100644
5485fb
--- a/src/libopensc/ctx.c
5485fb
+++ b/src/libopensc/ctx.c
5485fb
@@ -1008,7 +1008,12 @@ int sc_get_cache_dir(sc_context_t *ctx, char *buf, size_t bufsize)
5485fb
 	}
5485fb
 
5485fb
 #ifndef _WIN32
5485fb
-	cache_dir = ".eid/cache";
5485fb
+	cache_dir = getenv("XDG_CACHE_HOME");
5485fb
+	if (cache_dir != NULL && cache_dir[0] != '\0') {
5485fb
+		snprintf(buf, bufsize, "%s/%s", cache_dir, "opensc");
5485fb
+		return SC_SUCCESS;
5485fb
+	}
5485fb
+	cache_dir = ".cache/opensc";
5485fb
 	homedir = getenv("HOME");
5485fb
 #else
5485fb
 	cache_dir = "eid-cache";
5485fb
@@ -1020,7 +1025,7 @@ int sc_get_cache_dir(sc_context_t *ctx, char *buf, size_t bufsize)
5485fb
 		homedir = temp_path;
5485fb
 	}
5485fb
 #endif
5485fb
-	if (homedir == NULL)
5485fb
+	if (homedir == NULL || homedir[0] == '\0')
5485fb
 		return SC_ERROR_INTERNAL;
5485fb
 	if (snprintf(buf, bufsize, "%s/%s", homedir, cache_dir) < 0)
5485fb
 		return SC_ERROR_BUFFER_TOO_SMALL;
5485fb
5485fb
From 7c1c6f6be47f55693647827259edcacc98761371 Mon Sep 17 00:00:00 2001
5485fb
From: Jakub Jelen <jjelen@redhat.com>
5485fb
Date: Tue, 10 Nov 2020 15:07:42 +0100
5485fb
Subject: [PATCH 3/3] doc: Update documentation about the cache location
5485fb
5485fb
---
5485fb
 doc/files/opensc.conf.5.xml.in | 9 +++++++--
5485fb
 2 files changed, 11 insertions(+), 4 deletions(-)
5485fb
5485fb
diff --git a/doc/files/opensc.conf.5.xml.in b/doc/files/opensc.conf.5.xml.in
5485fb
index 118922a877..791f11669a 100644
5485fb
--- a/doc/files/opensc.conf.5.xml.in
5485fb
+++ b/doc/files/opensc.conf.5.xml.in
5485fb
@@ -1116,12 +1116,17 @@ app <replaceable>application</replaceable> {
5485fb
 							<itemizedlist>
5485fb
 								<listitem>
5485fb
 									<para>
5485fb
-										<filename><envar>HOME</envar>/.eid/cache/</filename> (Unix)
5485fb
+										<filename><envar>$XDG_CACHE_HOME</envar>/opensc/</filename> (If <envar>$XDG_CACHE_HOME</envar> is defined)
5485fb
 									</para>
5485fb
 								</listitem>
5485fb
 								<listitem>
5485fb
 									<para>
5485fb
-										<filename><envar>USERPROFILE</envar>\.eid-cache\</filename> (Windows)
5485fb
+										<filename><envar>$HOME</envar>/.cache/opensc/</filename> (Unix)
5485fb
+									</para>
5485fb
+								</listitem>
5485fb
+								<listitem>
5485fb
+									<para>
5485fb
+										<filename><envar>$USERPROFILE</envar>\.eid-cache\</filename> (Windows)
5485fb
 									</para>
5485fb
 								</listitem>
5485fb
 							</itemizedlist>
5485fb
5485fb
diff -up opensc-0.20.0/etc/opensc.conf.file-cache opensc-0.20.0/etc/opensc.conf
5485fb
--- opensc-0.20.0/etc/opensc.conf.file-cache	2020-11-20 16:49:30.995526825 +0100
5485fb
+++ opensc-0.20.0/etc/opensc.conf	2020-11-20 16:50:07.665053280 +0100
5485fb
@@ -2,7 +2,7 @@ app default {
5485fb
 	# debug = 3;
5485fb
 	# debug_file = opensc-debug.txt;
5485fb
 	framework pkcs15 {
5485fb
-		# use_file_caching = true;
5485fb
+		use_file_caching = true;
5485fb
 	}
5485fb
 	reader_driver pcsc {
5485fb
 		# The pinpad is disabled by default,
5485fb