mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
util: Rewrite virGetUserCacheDirectory() using g_get_user_cache_dir()
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
e59b946ce4
commit
520e626e7e
@ -596,6 +596,16 @@ char *virGetUserConfigDirectory(void)
|
||||
}
|
||||
|
||||
|
||||
char *virGetUserCacheDirectory(void)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return g_strdup(g_get_user_cache_dir());
|
||||
#else
|
||||
return g_build_filename(g_get_user_cache_dir(), "libvirt", NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GETPWUID_R
|
||||
/* Look up fields from the user database for the given user. On
|
||||
* error, set errno, report the error if not instructed otherwise via @quiet,
|
||||
@ -746,29 +756,6 @@ char *virGetUserShell(uid_t uid)
|
||||
}
|
||||
|
||||
|
||||
static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir)
|
||||
{
|
||||
const char *path = getenv(xdgenvname);
|
||||
char *ret = NULL;
|
||||
char *home = NULL;
|
||||
|
||||
if (path && path[0]) {
|
||||
ret = g_strdup_printf("%s/libvirt", path);
|
||||
} else {
|
||||
home = virGetUserDirectory();
|
||||
if (home)
|
||||
ret = g_strdup_printf("%s/%s/libvirt", home, xdgdefdir);
|
||||
}
|
||||
|
||||
VIR_FREE(home);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *virGetUserCacheDirectory(void)
|
||||
{
|
||||
return virGetXDGDirectory("XDG_CACHE_HOME", ".cache");
|
||||
}
|
||||
|
||||
char *virGetUserRuntimeDirectory(void)
|
||||
{
|
||||
const char *path = getenv("XDG_RUNTIME_DIR");
|
||||
@ -1192,21 +1179,6 @@ virGetUserShell(uid_t uid G_GNUC_UNUSED)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
virGetUserCacheDirectory(void)
|
||||
{
|
||||
char *ret;
|
||||
if (virGetWin32SpecialFolder(CSIDL_INTERNET_CACHE, &ret) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!ret) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to determine config directory"));
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
virGetUserRuntimeDirectory(void)
|
||||
{
|
||||
@ -1232,15 +1204,6 @@ virGetUserShell(uid_t uid G_GNUC_UNUSED)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
virGetUserCacheDirectory(void)
|
||||
{
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("virGetUserCacheDirectory is not available"));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
virGetUserRuntimeDirectory(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user