/* * Copyright (C) 2014 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include #include "plover/uri-handler.h" G_DEFINE_TYPE(PloverRepository,plover_repository,G_TYPE_OBJECT); typedef struct _PloverRepositoryPrivate { PloverPackageSet *set; gchar **uris; } PloverRepositoryPrivate; #define PLOVER_REPOSITORY_GET_PRIVATE(obj)\ G_TYPE_INSTANCE_GET_PRIVATE(obj,\ PLOVER_TYPE_REPOSITORY,\ PloverRepositoryPrivate) static void plover_repository_finalize(GObject *obj) { PloverRepositoryPrivate *priv=PLOVER_REPOSITORY_GET_PRIVATE(obj); g_strfreev(priv->uris); if (G_OBJECT_CLASS(plover_repository_parent_class)->finalize) G_OBJECT_CLASS(plover_repository_parent_class)->finalize(obj); } static void plover_repository_dispose(GObject *obj) { PloverRepositoryPrivate *priv=PLOVER_REPOSITORY_GET_PRIVATE(obj); g_clear_object(&priv->set); if (G_OBJECT_CLASS(plover_repository_parent_class)->dispose) G_OBJECT_CLASS(plover_repository_parent_class)->dispose(obj); } static void plover_repository_class_init(PloverRepositoryClass *klass) { GObjectClass *oclass=G_OBJECT_CLASS(klass); plover__uri_handler_init(); oclass->finalize=plover_repository_finalize; oclass->dispose=plover_repository_dispose; g_type_class_add_private(klass,sizeof(PloverRepositoryPrivate)); } static void plover_repository_init(PloverRepository *repository) { } PloverRepository *plover_repository_new_from_package_set(PloverPackageSet *set, const char **rpm_uris) { PloverRepository *repository; PloverRepositoryPrivate *priv; g_return_val_if_fail(PLOVER_IS_PACKAGE_SET(set),NULL); g_return_val_if_fail(rpm_uris != NULL,NULL); repository=g_object_new(PLOVER_TYPE_REPOSITORY,NULL); priv=PLOVER_REPOSITORY_GET_PRIVATE(repository); priv->uris=g_strdupv((char **)rpm_uris); priv->set=g_object_ref(set); return repository; } PloverRepository *plover_repository_new_from_files(const char **filenames, GError **error) { int i; PloverPackageSet *set; PloverRepository *repository; PloverRepositoryPrivate *priv; GFile *file; gchar *uri; set=plover_package_set_new_from_rpms(filenames,error); if (!set) return NULL; repository=g_object_new(PLOVER_TYPE_REPOSITORY,NULL); priv=PLOVER_REPOSITORY_GET_PRIVATE(repository); priv->uris=g_new(char *,g_strv_length((char **)filenames)+1); for(i=0;filenames[i];i++) { file=g_file_new_for_path(filenames[i]); priv->uris[i]=g_file_get_uri(file); g_object_unref(file); } priv->uris[i]=NULL; priv->set=set; return repository; } static char *rpm_filename(const char *name,const char *version,const char *arch) { const char *v; v=strchr(version,':'); /* Skip epoch */ if (v) v++; else v=version; return g_strconcat(name,"-",v,".",arch,".rpm",NULL); } PloverRepository *plover_repository_new_from_yum(const char *base, GError **error) { PloverRepository *repository; gchar *base_uri; GFile *file; file=g_file_new_for_path(base); base_uri=g_file_get_uri(file); g_object_unref(file); repository=plover_repository_new_from_yum_uri(base_uri,error); g_free(base_uri); return repository; } PloverPackageSet * plover_repository_get_package_set(PloverRepository *repository) { PloverRepositoryPrivate *priv; g_return_val_if_fail(PLOVER_IS_REPOSITORY(repository),NULL); priv=PLOVER_REPOSITORY_GET_PRIVATE(repository); return priv->set; } struct razor_rpm *plover_repository_open_rpm(PloverRepository *repository, PloverPackage *package,GError **error) { int nth; struct razor_rpm *rpm; struct razor_error *tmp_error=NULL; PloverRepositoryPrivate *priv; PloverPackage *internal; g_return_val_if_fail(PLOVER_IS_REPOSITORY(repository),NULL); g_return_val_if_fail(PLOVER_IS_PACKAGE(package),NULL); priv=PLOVER_REPOSITORY_GET_PRIVATE(repository); nth=g_slist_index(plover_package_set_get_packages(priv->set),package); if (nth<0) { internal=plover_package_set_find_matching(priv->set,package); nth=g_slist_index(plover_package_set_get_packages(priv->set),internal); } if (nth<0) { g_set_error(error,PLOVER_GENERAL_ERROR, PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE, "%s-%s.%s: Package not in repository", plover_package_get_name(package),plover_package_get_version(package), plover_package_get_arch(package)); return NULL; } rpm=razor_rpm_open(priv->uris[nth],&tmp_error); if (!rpm) plover_propagate_razor_error(error,tmp_error); return rpm; }