# HG changeset patch # User J. Ali Harlow # Date 1465904393 -3600 # Node ID bd50a4b7ab6837d2432a49ecb514dce540f2a3a2 # Parent e61a449e94cb09b6c8f2484f754bffb311cf3a4f First tentative step in using razor_file_set_vtable diff -r e61a449e94cb -r bd50a4b7ab68 plover/Makefile.am --- a/plover/Makefile.am Mon Jun 13 12:19:50 2016 +0100 +++ b/plover/Makefile.am Tue Jun 14 12:39:53 2016 +0100 @@ -3,14 +3,14 @@ LIBS=$(LIBPLOVER_LIBS) INCLUDES=-I$(top_srcdir) AM_LDFLAGS=-no-undefined -version-info $(LIBPLOVER_LT_VERSION_INFO) \ - $(CODE_COVERAGE_LDFLAGS) + $(CODE_COVERAGE_LDFLAGS) -export-symbols-regex '^plover_[^_]' pkginclude_HEADERS=plover.h transaction.h package.h packageset.h repository.h lib_LTLIBRARIES=libplover.la libplover_la_SOURCES=$(pkginclude_HEADERS) util.c import-yum.c razor.c comps.c \ log.c vector.c transaction.c package.c packageset.c repository.c \ - exception-handler.cpp + fileio.c fileio.h exception-handler.cpp pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=plover.pc diff -r e61a449e94cb -r bd50a4b7ab68 plover/fileio.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plover/fileio.c Tue Jun 14 12:39:53 2016 +0100 @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 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 +#include +#include +#include +#include "config.h" +#include "plover/plover.h" + +static GList *open_razor_files; + +static void *file_get_contents(const char *uri,size_t *length,int private, + struct razor_error **error) +{ + GFile *file; + gchar *path; + void *addr; + char *contents; + gsize len; + GError *err=NULL; + g_message("file_get_contents(%s)",uri); + file=g_file_new_for_uri(uri); + path=g_file_get_path(file); + if (path) + { + g_object_unref(file); + addr=razor_file_default_get_contents(path,length,private,error); + if (addr) + open_razor_files=g_list_prepend(open_razor_files,addr); + g_free(path); + } + else if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err)) + { + plover_propagate_g_error(error,err); + g_object_unref(file); + addr=NULL; + } + else + { + g_object_unref(file); + addr=contents; + if (length) + *length=len; + } + return addr; +} + +static int file_free_contents(void *addr,size_t length) +{ + int retval; + GList *lnk; + g_message("file_free_contents(%p)",addr); + lnk=g_list_find(open_razor_files,addr); + if (lnk) + { + open_razor_files=g_list_delete_link(open_razor_files,lnk); + retval=razor_file_default_free_contents(addr,length); + } + else + { + g_free(addr); + retval=0; + } + return retval; +} + +void plover__file_io_init(void) +{ + static gsize init=0; + struct razor_file_vtable file_vtable; + g_message("plover__file_io_init()"); + if (g_once_init_enter(&init)) + { + file_vtable.get_contents=file_get_contents; + file_vtable.free_contents=file_free_contents; + razor_file_set_vtable(&file_vtable); + g_once_init_leave(&init,1); + } +} diff -r e61a449e94cb -r bd50a4b7ab68 plover/razor.c --- a/plover/razor.c Mon Jun 13 12:19:50 2016 +0100 +++ b/plover/razor.c Tue Jun 14 12:39:53 2016 +0100 @@ -239,17 +239,21 @@ int len,matches=1; const char *name; char *install_root; + GFile *file; struct razor_set *set; struct razor_package *package; struct razor_package_iterator *pi; struct razor_file_iterator *fi; + plover__file_io_init(); len=strlen(prefix); while(len && prefix[len-1]=='/') len--; install_root=getenv("RAZOR_ROOT"); if (!install_root) install_root=""; - set=razor_root_open_read_only(install_root,NULL); + file=g_file_new_for_path(*install_root?install_root:"/"); + set=razor_root_open_read_only(g_file_get_uri(file),NULL); + g_object_unref(file); if (set) { pi=razor_package_iterator_create(set);