Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using xml:base with microdnf and packagekit #833

Merged
merged 2 commits into from Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions libdnf/dnf-package.cpp
Expand Up @@ -35,6 +35,7 @@
#include <fcntl.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <assert.h>

#include <librepo/librepo.h>
#include <memory>
Expand Down Expand Up @@ -89,6 +90,29 @@ dnf_package_get_priv(DnfPackage *pkg)
return priv;
}

/**
* dnf_package_is_local:
* @pkg: a #DnfPackage *instance.
*
* Returns: %TRUE if the pkg is a pkg on local or media filesystem
*
* Since: 0.38.2
**/
gboolean
dnf_package_is_local(DnfPackage *pkg)
{
DnfPackagePrivate *priv;
priv = dnf_package_get_priv(pkg);

assert(priv->repo);

if (!dnf_repo_is_local(priv->repo))
return FALSE;

const gchar *url_location = dnf_package_get_baseurl(pkg);
return (!url_location || (url_location && g_str_has_prefix(url_location, "file:/")));
}

/**
* dnf_package_get_filename:
* @pkg: a #DnfPackage *instance.
Expand All @@ -114,7 +138,7 @@ dnf_package_get_filename(DnfPackage *pkg)

/* default cache filename location */
if (!priv->filename) {
if (dnf_repo_is_local(priv->repo)) {
if (dnf_package_is_local(pkg)) {
const gchar *url_location = dnf_package_get_baseurl(pkg);
if (!url_location){
url_location = dnf_repo_get_location(priv->repo);
Expand Down Expand Up @@ -660,9 +684,9 @@ dnf_package_check_filename(DnfPackage *pkg, gboolean *valid, GError **error)
if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
*valid = FALSE;

/* a missing file in a local repo is an error since we can't
download it. */
if (dnf_repo_is_local (dnf_package_get_repo (pkg))) {
/* a missing file in a local repo is an error, unless it is remote via base:url,
* since we can't download it */
if (dnf_package_is_local(pkg)) {
ret = FALSE;
g_set_error(error,
DNF_ERROR,
Expand Down
1 change: 1 addition & 0 deletions libdnf/dnf-package.h
Expand Up @@ -78,6 +78,7 @@ void dnf_package_set_user_action (DnfPackage *pkg,
gboolean user_action);
gboolean dnf_package_is_gui (DnfPackage *pkg);
gboolean dnf_package_is_devel (DnfPackage *pkg);
gboolean dnf_package_is_local (DnfPackage *pkg);
gboolean dnf_package_is_downloaded (DnfPackage *pkg);
gboolean dnf_package_is_installonly (DnfPackage *pkg);
const gchar *dnf_package_get_pkgid (DnfPackage *pkg);
Expand Down
41 changes: 18 additions & 23 deletions libdnf/dnf-repo.cpp
Expand Up @@ -1010,27 +1010,33 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, GError **error)
if (url != NULL && strncasecmp(url, "file://", 7) == 0) {
if (g_strstr_len(url, -1, "$testdatadir") == NULL)
priv->kind = DNF_REPO_KIND_LOCAL;
dnf_repo_set_location(repo, url + 7);
g_free(priv->location);
g_free(priv->keyring);
priv->location = dnf_repo_substitute(repo, url + 7);
priv->keyring = g_build_filename(url + 7, "gpgdir", NULL);
}
}

/* set location if currently unset */
if (!lr_handle_setopt(priv->repo_handle, error, LRO_LOCAL, 0L))
return FALSE;

if (priv->location == NULL) {
g_autofree gchar *tmp = NULL;
/* make each repo's cache directory name has releasever and basearch as its suffix */
g_autofree gchar *file_name = g_strjoin("-", repoId,
dnf_context_get_release_ver(priv->context),
dnf_context_get_base_arch(priv->context), NULL);
/* set repos cache dir */
g_autofree gchar *cache_path = NULL;
/* make each repo's cache directory name has releasever and basearch as its suffix */
g_autofree gchar *cache_file_name = g_strjoin("-", repoId,
dnf_context_get_release_ver(priv->context),
dnf_context_get_base_arch(priv->context), NULL);

tmp = g_build_filename(dnf_context_get_cache_dir(priv->context),
file_name, NULL);
dnf_repo_set_location(repo, tmp);
cache_path = g_build_filename(dnf_context_get_cache_dir(priv->context), cache_file_name, NULL);
if (priv->packages == NULL) {
dnf_repo_set_packages(repo, g_build_filename(cache_path, "packages", NULL));
}
if (priv->location == NULL) {
dnf_repo_set_location(repo, cache_path);
}

/* set temp location for remote repos */
/* set temp location used for updating remote repos */
if (priv->kind == DNF_REPO_KIND_REMOTE) {
g_autoptr(GString) tmp = NULL;
tmp = g_string_new(priv->location);
Expand Down Expand Up @@ -2162,22 +2168,11 @@ dnf_repo_download_packages(DnfRepo *repo,
if (!dnf_repo_set_keyfile_data(repo, error))
goto out;

/* we should never be asked to download from a local repo. if
this happens, it's a bug somewhere else. */
if (dnf_repo_is_local(repo)) {
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
"Refusing to download from local repository \"%s\"",
priv->repo->getId().c_str());
goto out;
}

/* if nothing specified then use cachedir */
if (directory == NULL) {
directory_slash = g_build_filename(priv->packages, "/", NULL);
if (!g_file_test(directory_slash, G_FILE_TEST_EXISTS)) {
if (g_mkdir(directory_slash, 0755) != 0) {
if (g_mkdir_with_parents(directory_slash, 0755) != 0) {
g_set_error(error,
DNF_ERROR,
DNF_ERROR_INTERNAL_ERROR,
Expand Down