1.1 --- a/plover/Makefile.am Mon Jun 13 12:19:50 2016 +0100
1.2 +++ b/plover/Makefile.am Tue Jun 14 12:39:53 2016 +0100
1.3 @@ -3,14 +3,14 @@
1.4 LIBS=$(LIBPLOVER_LIBS)
1.5 INCLUDES=-I$(top_srcdir)
1.6 AM_LDFLAGS=-no-undefined -version-info $(LIBPLOVER_LT_VERSION_INFO) \
1.7 - $(CODE_COVERAGE_LDFLAGS)
1.8 + $(CODE_COVERAGE_LDFLAGS) -export-symbols-regex '^plover_[^_]'
1.9
1.10 pkginclude_HEADERS=plover.h transaction.h package.h packageset.h repository.h
1.11
1.12 lib_LTLIBRARIES=libplover.la
1.13 libplover_la_SOURCES=$(pkginclude_HEADERS) util.c import-yum.c razor.c comps.c \
1.14 log.c vector.c transaction.c package.c packageset.c repository.c \
1.15 - exception-handler.cpp
1.16 + fileio.c fileio.h exception-handler.cpp
1.17
1.18 pkgconfigdir=$(libdir)/pkgconfig
1.19 pkgconfig_DATA=plover.pc
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/plover/fileio.c Tue Jun 14 12:39:53 2016 +0100
2.3 @@ -0,0 +1,95 @@
2.4 +/*
2.5 + * Copyright (C) 2016 J. Ali Harlow <ali@juiblex.co.uk>
2.6 + *
2.7 + * This program is free software; you can redistribute it and/or modify
2.8 + * it under the terms of the GNU General Public License as published by
2.9 + * the Free Software Foundation; either version 2 of the License, or
2.10 + * (at your option) any later version.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License along
2.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
2.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2.20 + */
2.21 +
2.22 +#include <stdlib.h>
2.23 +#include <razor.h>
2.24 +#include <glib.h>
2.25 +#include <gio/gio.h>
2.26 +#include "config.h"
2.27 +#include "plover/plover.h"
2.28 +
2.29 +static GList *open_razor_files;
2.30 +
2.31 +static void *file_get_contents(const char *uri,size_t *length,int private,
2.32 + struct razor_error **error)
2.33 +{
2.34 + GFile *file;
2.35 + gchar *path;
2.36 + void *addr;
2.37 + char *contents;
2.38 + gsize len;
2.39 + GError *err=NULL;
2.40 + g_message("file_get_contents(%s)",uri);
2.41 + file=g_file_new_for_uri(uri);
2.42 + path=g_file_get_path(file);
2.43 + if (path)
2.44 + {
2.45 + g_object_unref(file);
2.46 + addr=razor_file_default_get_contents(path,length,private,error);
2.47 + if (addr)
2.48 + open_razor_files=g_list_prepend(open_razor_files,addr);
2.49 + g_free(path);
2.50 + }
2.51 + else if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err))
2.52 + {
2.53 + plover_propagate_g_error(error,err);
2.54 + g_object_unref(file);
2.55 + addr=NULL;
2.56 + }
2.57 + else
2.58 + {
2.59 + g_object_unref(file);
2.60 + addr=contents;
2.61 + if (length)
2.62 + *length=len;
2.63 + }
2.64 + return addr;
2.65 +}
2.66 +
2.67 +static int file_free_contents(void *addr,size_t length)
2.68 +{
2.69 + int retval;
2.70 + GList *lnk;
2.71 + g_message("file_free_contents(%p)",addr);
2.72 + lnk=g_list_find(open_razor_files,addr);
2.73 + if (lnk)
2.74 + {
2.75 + open_razor_files=g_list_delete_link(open_razor_files,lnk);
2.76 + retval=razor_file_default_free_contents(addr,length);
2.77 + }
2.78 + else
2.79 + {
2.80 + g_free(addr);
2.81 + retval=0;
2.82 + }
2.83 + return retval;
2.84 +}
2.85 +
2.86 +void plover__file_io_init(void)
2.87 +{
2.88 + static gsize init=0;
2.89 + struct razor_file_vtable file_vtable;
2.90 + g_message("plover__file_io_init()");
2.91 + if (g_once_init_enter(&init))
2.92 + {
2.93 + file_vtable.get_contents=file_get_contents;
2.94 + file_vtable.free_contents=file_free_contents;
2.95 + razor_file_set_vtable(&file_vtable);
2.96 + g_once_init_leave(&init,1);
2.97 + }
2.98 +}
3.1 --- a/plover/razor.c Mon Jun 13 12:19:50 2016 +0100
3.2 +++ b/plover/razor.c Tue Jun 14 12:39:53 2016 +0100
3.3 @@ -239,17 +239,21 @@
3.4 int len,matches=1;
3.5 const char *name;
3.6 char *install_root;
3.7 + GFile *file;
3.8 struct razor_set *set;
3.9 struct razor_package *package;
3.10 struct razor_package_iterator *pi;
3.11 struct razor_file_iterator *fi;
3.12 + plover__file_io_init();
3.13 len=strlen(prefix);
3.14 while(len && prefix[len-1]=='/')
3.15 len--;
3.16 install_root=getenv("RAZOR_ROOT");
3.17 if (!install_root)
3.18 install_root="";
3.19 - set=razor_root_open_read_only(install_root,NULL);
3.20 + file=g_file_new_for_path(*install_root?install_root:"/");
3.21 + set=razor_root_open_read_only(g_file_get_uri(file),NULL);
3.22 + g_object_unref(file);
3.23 if (set)
3.24 {
3.25 pi=razor_package_iterator_create(set);