This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] debuginfod-client: update cache_path when new default path exists


From 46010f911b72610452c2c58a709af8609992225b Mon Sep 17 00:00:00 2001
From: Aaron Merey <amerey@redhat.com>
Date: Tue, 3 Mar 2020 14:11:48 -0500
Subject: [PATCH] debuginfod-client: Update cache_path when the new default
 path exists

Update cache_path with the path of the new default directory when this
directory already exists. Previously cache_path was updated only when
creating the new default directory and would otherwise be set to the
old default path.

Signed-off-by: Aaron Merey <amerey@redhat.com>
---
 debuginfod/ChangeLog           |  5 +++++
 debuginfod/debuginfod-client.c | 16 +++++++---------
 tests/run-debuginfod-find.sh   |  7 +++++++
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 21d9ed87..ab32b523 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-03  Aaron Merey  <amerey@redhat.com>
+
+	* debuginfod-client.c (debuginfod_query_server): Update
+	cache_path even when new default path already exists.
+
 2020-02-27  Aaron Merey  <amerey@redhat.com>
 
 	* debuginfod-client.c (xalloc_str): New macro. Call
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 2825e625..8923099f 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -509,20 +509,18 @@ debuginfod_query_server (debuginfod_client *c,
 
               /* Also check for EEXIST and S_ISDIR in case another client just
                  happened to create the cache.  */
-              if (rc == 0
-                  || (errno == EEXIST
-                      && stat (cachedir, &st) != 0
-                      && S_ISDIR (st.st_mode)))
-                {
-                  free (cache_path);
-                  xalloc_str (cache_path, "%s/%s", cachedir, cache_xdg_name);
-                }
-              else
+              if (rc < 0
+                  && (errno != EEXIST
+                      || stat (cachedir, &st) != 0
+                      || ! S_ISDIR (st.st_mode)))
                 {
                   rc = -errno;
                   goto out;
                 }
             }
+
+          free (cache_path);
+          xalloc_str (cache_path, "%s/%s", cachedir, cache_xdg_name);
         }
     }
 
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 56e61216..587eaaa3 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -158,6 +158,13 @@ if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then
   exit 1
 fi
 
+# $HOME/.cache should be found.
+testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID
+if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then
+  echo "could not find cache in $PWD/tmphome/.cache"
+  exit 1
+fi
+
 # $XDG_CACHE_HOME should take priority over $HOME.cache.
 testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
 if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then
-- 
2.24.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]