# HG changeset patch # User J. Ali Harlow # Date 1466611468 -3600 # Node ID 43ffed8669ceef44931bddb68ff8c6715db6f8aa # Parent 6b3034a884dcf6d8c9f2eed87a0bc2072f9ac2ac Port to razor 0.6.3.60 diff -r 6b3034a884dc -r 43ffed8669ce plover-gtk/transactionhelper.c --- a/plover-gtk/transactionhelper.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover-gtk/transactionhelper.c Wed Jun 22 17:04:28 2016 +0100 @@ -23,6 +23,7 @@ #include #include #include +#include "plover/uri-handler.h" /* * A PloverTransactionHelper uses a GtkAssistant to help a user run a @@ -95,7 +96,7 @@ static void plover_transaction_helper_class_init(PloverTransactionHelperClass *klass) { - plover__file_io_init(); + plover__uri_handler_init(); GObjectClass *gobject_class=G_OBJECT_CLASS(klass); gobject_class->finalize= (void (*)(GObject *))plover_transaction_helper_finalize; diff -r 6b3034a884dc -r 43ffed8669ce plover/Makefile.am --- a/plover/Makefile.am Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/Makefile.am Wed Jun 22 17:04:28 2016 +0100 @@ -10,7 +10,7 @@ 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 \ - fileio.c fileio.h exception-handler.cpp + uri-handler.c uri-handler.h exception-handler.cpp pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=plover.pc diff -r 6b3034a884dc -r 43ffed8669ce plover/comps.c --- a/plover/comps.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/comps.c Wed Jun 22 17:04:28 2016 +0100 @@ -24,6 +24,7 @@ #include #include #include "plover/plover.h" +#include "plover/uri-handler.h" /* Parse a comps.xml package group file. */ @@ -381,7 +382,7 @@ GFileInputStream *stream; XML_ParsingStatus status; struct comps *comps; - plover__file_io_init(); + plover__uri_handler_init(); file=g_file_new_for_uri(uri); stream=g_file_read(file,NULL,NULL); g_object_unref(file); diff -r 6b3034a884dc -r 43ffed8669ce plover/fileio.c --- a/plover/fileio.c Thu Jun 16 18:00:21 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,417 +0,0 @@ -/* - * 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 -#include -#include "config.h" -#include "plover/plover.h" - -static GList *open_razor_files; - -static gboolean has_valid_scheme(const char *uri) -{ - /* - * RFC 2396 defines valid schemes as: - * scheme = alpha *( alpha | digit | "+" | "-" | "." ) - */ - const char *s; - if (!g_ascii_isalpha(*uri)) - return FALSE; - for(s=uri+1;;s++) - if (*s==':') - return TRUE; - else if (!g_ascii_isalnum(*s) && *s!='+' && *s!='-' && *s!='.') - return FALSE; -} - -static GFile *file_for_uri(const char *uri) -{ - GFile *file; - if (!has_valid_scheme(uri)) - { - g_warning("%s: Not a valid URI",uri); - file=g_file_new_for_path(uri); - } - else - { - if (strstr(uri+1,"file:/")) - g_warning("%s: Implausible URI",uri); - file=g_file_new_for_uri(uri); - } - return file; -} - -int file_mkdir(const char *uri,mode_t mode,struct razor_error **error) -{ - GFile *file; - GFileInfo *info; - gchar *path; - int retval; - GError *err=NULL; - g_message("file_mkdir(%s)",uri); - file=file_for_uri(uri); - path=g_file_get_path(file); - if (path) - { - retval=razor_file_default_mkdir(path,mode,error); - g_free(path); - } - else if (!g_file_make_directory(file,NULL,&err)) - { - retval=-1; - if (g_error_matches(err,G_IO_ERROR,G_IO_ERROR_EXISTS)) - { - info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,NULL); - if (info) - { - g_clear_error(&err); - if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY) - retval=0; - else - razor_set_error(error,RAZOR_POSIX_ERROR,EEXIST,uri, - "Not a directory"); - g_object_unref(info); - } - } - if (err) - plover_propagate_g_error(error,err); - } - else - retval=0; - g_object_unref(file); - return retval; -} - -int file_unlink(const char *uri,struct razor_error **error) -{ - GFile *file; - gchar *path; - int retval; - GError *err=NULL; - g_message("file_unlink(%s)",uri); - file=file_for_uri(uri); - path=g_file_get_path(file); - if (path) - { - retval=razor_file_default_unlink(path,error); - g_free(path); - } - else if (!g_file_delete(file,NULL,&err)) - { - plover_propagate_g_error(error,err); - retval=-1; - } - else - retval=0; - g_object_unref(file); - return retval; -} - -int file_open(const char *uri,int flags,mode_t mode,struct razor_error **error) -{ - GFile *file; - gchar *path; - int retval; - GError *err=NULL; - g_message("file_open(%s)",uri); - file=file_for_uri(uri); - path=g_file_get_path(file); - if (path) - { - retval=razor_file_default_open(path,flags,mode,error); - g_free(path); - } - else - { - razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED, - uri,"File is not local"); - retval=-1; - } - g_object_unref(file); - return retval; -} - -int file_move(const char *src_uri,const char *dst_uri, - struct razor_error **error) -{ - GFile *src,*dst; - gchar *src_path,*dst_path; - int retval; - GError *err=NULL; - g_message("file_move(%s,%s)",src_uri,dst_uri); - src=file_for_uri(src_uri); - dst=file_for_uri(dst_uri); - src_path=g_file_get_path(src); - dst_path=g_file_get_path(dst); - if (src_path && dst_path) - retval=razor_file_default_move(src_path,dst_path,error); - else if (!g_file_move(src,dst,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&err)) - { - plover_propagate_g_error(error,err); - retval=-1; - } - else - retval=0; - g_free(src_path); - g_free(dst_path); - g_object_unref(src); - g_object_unref(dst); - return retval; -} - -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=file_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; -} - -int file_is_directory(const char *uri,struct razor_error **error) -{ - GFile *file; - GFileInfo *info; - gchar *path; - int retval; - GError *err=NULL; - g_message("file_is_directory(%s)",uri); - file=file_for_uri(uri); - path=g_file_get_path(file); - if (path) - { - retval=razor_file_default_is_directory(path,error); - g_free(path); - } - else - { - info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err); - if (info) - { - if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY) - retval=1; - else - retval=0; - g_object_unref(info); - } - else - { - retval=-1; - plover_propagate_g_error(error,err); - } - } - g_object_unref(file); - return retval; -} - -char *file_mkdtemp_near(const char *uri,const char *template, - struct razor_error **error) -{ - GFile *file; - gchar *path,*tmpuri; - char *tmppath,*retval; - GError *err=NULL; - g_message("file_mkdtemp_near(%s)",uri); - file=file_for_uri(uri); - path=g_file_get_path(file); - g_object_unref(file); - if (path) - { - tmppath=razor_file_default_mkdtemp_near(path,template,error); - g_free(path); - if (tmppath) - { - file=g_file_new_for_path(tmppath); - tmpuri=g_file_get_uri(file); - g_object_unref(file); - retval=strdup(tmpuri); - g_free(tmpuri); - } - else - retval=NULL; - } - else - { - razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED, - uri,"File is not local"); - retval=NULL; - } - return retval; -} - -struct file_dir { - void *razor_file_default; - GFileEnumerator *enumerator; -}; - -void *file_opendir(const char *uri,struct razor_error **error) -{ - GFile *file; - gchar *path; - struct file_dir *dir; - GError *err=NULL; - g_message("file_opendir(%s)",uri); - dir=g_new0(struct file_dir,1); - file=file_for_uri(uri); - path=g_file_get_path(file); - if (path) - { - dir->razor_file_default=razor_file_default_opendir(path,error); - if (!dir->razor_file_default) - { - g_free(dir); - dir=NULL; - } - g_free(path); - } - else - { - dir->enumerator=g_file_enumerate_children(file, - G_FILE_ATTRIBUTE_STANDARD_NAME,G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL,&err); - if (!dir->enumerator) - { - g_free(dir); - dir=NULL; - plover_propagate_g_error(error,err); - } - } - g_object_unref(file); - return dir; -} - -char *file_readdir(void *dp,struct razor_error **error) -{ - struct file_dir *dir=dp; - char *name; - GError *err=NULL; - GFileInfo *info; - g_message("file_readdir(%p)",dp); - if (dir->razor_file_default) - name=razor_file_default_readdir(dir->razor_file_default,error); - else - { - info=g_file_enumerator_next_file(dir->enumerator,NULL,&err); - if (!info) - { - name=NULL; - plover_propagate_g_error(error,err); - } - else - { - name=strdup(g_file_info_get_name(info)); - g_object_unref(info); - } - } - return name; -} - -int file_closedir(void *dp,struct razor_error **error) -{ - struct file_dir *dir=dp; - int retval; - GError *err=NULL; - g_message("file_closedir(%p)",dp); - if (dir->razor_file_default) - retval=razor_file_default_closedir(dir->razor_file_default,error); - else - { - retval=g_file_enumerator_close(dir->enumerator,NULL,&err)?0:-1; - if (retval) - plover_propagate_g_error(error,err); - g_object_unref(dir->enumerator); - } - g_free(dir); - return retval; -} - -void plover__file_io_init(void) -{ - static gsize init=0; - struct razor_file_vtable file_vtable={0,}; - g_message("plover__file_io_init()"); - if (g_once_init_enter(&init)) - { - file_vtable.structure_size=sizeof(file_vtable); - file_vtable.mkdir=file_mkdir; - file_vtable.unlink=file_unlink; - file_vtable.open=file_open; - file_vtable.move=file_move; - file_vtable.get_contents=file_get_contents; - file_vtable.free_contents=file_free_contents; - file_vtable.is_directory=file_is_directory; - file_vtable.mkdtemp_near=file_mkdtemp_near; - file_vtable.opendir=file_opendir; - file_vtable.readdir=file_readdir; - file_vtable.closedir=file_closedir; - razor_file_set_vtable(&file_vtable); - g_once_init_leave(&init,1); - } -} diff -r 6b3034a884dc -r 43ffed8669ce plover/fileio.h --- a/plover/fileio.h Thu Jun 16 18:00:21 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#ifndef __FILEIO_H__ -#define __FILEIO_H__ - -G_BEGIN_DECLS - -void plover__file_io_init(void); - -G_END_DECLS - -#endif /* __FILEIO_H__ */ diff -r 6b3034a884dc -r 43ffed8669ce plover/import-yum.c --- a/plover/import-yum.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/import-yum.c Wed Jun 22 17:04:28 2016 +0100 @@ -32,7 +32,8 @@ #include #include #include -#include "plover.h" +#include "plover/plover.h" +#include "plover/uri-handler.h" /* Import a yum filelist as a razor package set. */ @@ -320,7 +321,7 @@ GZlibDecompressor *decompressor; XML_ParsingStatus status; struct razor_set *set; - plover__file_io_init(); + plover__uri_handler_init(); ctx.importer=razor_importer_create(); ctx.state=YUM_STATE_BEGIN; ctx.primary_parser=XML_ParserCreate(NULL); diff -r 6b3034a884dc -r 43ffed8669ce plover/log.c --- a/plover/log.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/log.c Wed Jun 22 17:04:28 2016 +0100 @@ -287,19 +287,36 @@ { int retval; char *root; - gchar *filename; + gchar *s,*filename; struct stat sb; time_t t; struct tm today,modified; struct razor_atomic *atomic; + struct razor_error *error=NULL; + GFile *base_file,*file; FILE *fp; root=getenv("RAZOR_ROOT"); if (root) - filename=g_strconcat(root,path,NULL); + { + base_file=g_file_new_for_uri(root); + file=g_file_resolve_relative_path(base_file,path); + g_object_unref(base_file); + filename=g_file_get_path(file); + if (!filename) + { + fprintf(stderr,"%s: Can't get local path\n",g_file_get_uri(file)); + g_object_unref(file); + return -1; + } + g_object_unref(file); + } else filename=g_strdup(path); atomic=razor_atomic_open("Open log"); - razor_atomic_make_dirs(atomic,"",filename); + if (root) + razor_atomic_make_dirs(atomic,root,path); + else + razor_atomic_make_dirs(atomic,"file:",path); retval=razor_atomic_commit(atomic); if (retval) fprintf(stderr,"Can't open log: %s\n", @@ -314,8 +331,7 @@ { if (errno!=ENOENT) { - fprintf(stderr,"Can't open log: "); - perror(filename); + perror("Can't open log"); g_free(filename); return -1; } diff -r 6b3034a884dc -r 43ffed8669ce plover/package.c --- a/plover/package.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/package.c Wed Jun 22 17:04:28 2016 +0100 @@ -22,6 +22,7 @@ #include #include #include "plover/package.h" +#include "plover/uri-handler.h" G_DEFINE_TYPE(PloverPackage,plover_package,G_TYPE_OBJECT); diff -r 6b3034a884dc -r 43ffed8669ce plover/packageset.c --- a/plover/packageset.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/packageset.c Wed Jun 22 17:04:28 2016 +0100 @@ -27,6 +27,7 @@ #include "plover/plover.h" #include "plover/package.h" #include "plover/packageset.h" +#include "plover/uri-handler.h" G_DEFINE_TYPE(PloverPackageSet,plover_package_set,G_TYPE_OBJECT); @@ -85,7 +86,7 @@ static void plover_package_set_class_init(PloverPackageSetClass *klass) { - plover__file_io_init(); + plover__uri_handler_init(); GObjectClass *oclass=G_OBJECT_CLASS(klass); oclass->finalize=plover_package_set_finalize; oclass->dispose=plover_package_set_dispose; @@ -373,7 +374,7 @@ struct razor_error *tmp_error=NULL; GFile *file; gchar *uri; - plover__file_io_init(); + plover__uri_handler_init(); importer=razor_importer_create(); for(i=0;filenames[i];i++) { diff -r 6b3034a884dc -r 43ffed8669ce plover/razor.c --- a/plover/razor.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/razor.c Wed Jun 22 17:04:28 2016 +0100 @@ -30,6 +30,7 @@ #include "config.h" #include "plover/plover.h" #include "plover/transaction.h" +#include "plover/uri-handler.h" static char *rpm_filename(const char *name,const char *version,const char *arch) { @@ -63,7 +64,7 @@ PloverPackage *package; GFile *file; gchar *uri; - plover__file_io_init(); + plover__uri_handler_init(); file=g_file_new_for_path(*install_root?install_root:"/"); uri=g_file_get_uri(file); g_object_unref(file); @@ -271,7 +272,7 @@ struct razor_package *package; struct razor_package_iterator *pi; struct razor_file_iterator *fi; - plover__file_io_init(); + plover__uri_handler_init(); len=strlen(prefix); while(len && prefix[len-1]=='/') len--; diff -r 6b3034a884dc -r 43ffed8669ce plover/repository.c --- a/plover/repository.c Thu Jun 16 18:00:21 2016 +0100 +++ b/plover/repository.c Wed Jun 22 17:04:28 2016 +0100 @@ -23,6 +23,7 @@ #include #include #include +#include "plover/uri-handler.h" G_DEFINE_TYPE(PloverRepository,plover_repository,G_TYPE_OBJECT); @@ -54,7 +55,7 @@ static void plover_repository_class_init(PloverRepositoryClass *klass) { - plover__file_io_init(); + plover__uri_handler_init(); GObjectClass *oclass=G_OBJECT_CLASS(klass); oclass->finalize=plover_repository_finalize; oclass->dispose=plover_repository_dispose; diff -r 6b3034a884dc -r 43ffed8669ce plover/uri-handler.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plover/uri-handler.c Wed Jun 22 17:04:28 2016 +0100 @@ -0,0 +1,418 @@ +/* + * 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 +#include +#include "config.h" +#include "plover/plover.h" +#include "uri-handler.h" + +static GList *open_razor_files; + +static gboolean has_valid_scheme(const char *uri) +{ + /* + * RFC 2396 defines valid schemes as: + * scheme = alpha *( alpha | digit | "+" | "-" | "." ) + */ + const char *s; + if (!g_ascii_isalpha(*uri)) + return FALSE; + for(s=uri+1;;s++) + if (*s==':') + return TRUE; + else if (!g_ascii_isalnum(*s) && *s!='+' && *s!='-' && *s!='.') + return FALSE; +} + +static GFile *file_for_uri(const char *uri) +{ + GFile *file; + if (!has_valid_scheme(uri)) + { + g_warning("%s: Not a valid URI",uri); + file=g_file_new_for_path(uri); + } + else + { + if (strstr(uri+1,"file:/")) + g_warning("%s: Implausible URI",uri); + file=g_file_new_for_uri(uri); + } + return file; +} + +int uri_mkdir(const char *uri,mode_t mode,struct razor_error **error) +{ + GFile *file; + GFileInfo *info; + gchar *path; + int retval; + GError *err=NULL; + g_message("uri_mkdir(%s)",uri); + file=file_for_uri(uri); + path=g_file_get_path(file); + if (path) + { + retval=razor_file_default_mkdir(path,mode,error); + g_free(path); + } + else if (!g_file_make_directory(file,NULL,&err)) + { + retval=-1; + if (g_error_matches(err,G_IO_ERROR,G_IO_ERROR_EXISTS)) + { + info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,NULL); + if (info) + { + g_clear_error(&err); + if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY) + retval=0; + else + razor_set_error(error,RAZOR_POSIX_ERROR,EEXIST,uri, + "Not a directory"); + g_object_unref(info); + } + } + if (err) + plover_propagate_g_error(error,err); + } + else + retval=0; + g_object_unref(file); + return retval; +} + +int uri_unlink(const char *uri,struct razor_error **error) +{ + GFile *file; + gchar *path; + int retval; + GError *err=NULL; + g_message("uri_unlink(%s)",uri); + file=file_for_uri(uri); + path=g_file_get_path(file); + if (path) + { + retval=razor_file_default_unlink(path,error); + g_free(path); + } + else if (!g_file_delete(file,NULL,&err)) + { + plover_propagate_g_error(error,err); + retval=-1; + } + else + retval=0; + g_object_unref(file); + return retval; +} + +int uri_open(const char *uri,int flags,mode_t mode,struct razor_error **error) +{ + GFile *file; + gchar *path; + int retval; + GError *err=NULL; + g_message("uri_open(%s)",uri); + file=file_for_uri(uri); + path=g_file_get_path(file); + if (path) + { + retval=razor_file_default_open(path,flags,mode,error); + g_free(path); + } + else + { + razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED, + uri,"File is not local"); + retval=-1; + } + g_object_unref(file); + return retval; +} + +int uri_move(const char *src_uri,const char *dst_uri, + struct razor_error **error) +{ + GFile *src,*dst; + gchar *src_path,*dst_path; + int retval; + GError *err=NULL; + g_message("uri_move(%s,%s)",src_uri,dst_uri); + src=file_for_uri(src_uri); + dst=file_for_uri(dst_uri); + src_path=g_file_get_path(src); + dst_path=g_file_get_path(dst); + if (src_path && dst_path) + retval=razor_file_default_move(src_path,dst_path,error); + else if (!g_file_move(src,dst,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&err)) + { + plover_propagate_g_error(error,err); + retval=-1; + } + else + retval=0; + g_free(src_path); + g_free(dst_path); + g_object_unref(src); + g_object_unref(dst); + return retval; +} + +static void *uri_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("uri_get_contents(%s)",uri); + file=file_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 uri_free_contents(void *addr,size_t length) +{ + int retval; + GList *lnk; + g_message("uri_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; +} + +int uri_is_directory(const char *uri,struct razor_error **error) +{ + GFile *file; + GFileInfo *info; + gchar *path; + int retval; + GError *err=NULL; + g_message("uri_is_directory(%s)",uri); + file=file_for_uri(uri); + path=g_file_get_path(file); + if (path) + { + retval=razor_file_default_is_directory(path,error); + g_free(path); + } + else + { + info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err); + if (info) + { + if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY) + retval=1; + else + retval=0; + g_object_unref(info); + } + else + { + retval=-1; + plover_propagate_g_error(error,err); + } + } + g_object_unref(file); + return retval; +} + +char *uri_mkdtemp_near(const char *uri,const char *template, + struct razor_error **error) +{ + GFile *file; + gchar *path,*tmpuri; + char *tmppath,*retval; + GError *err=NULL; + g_message("uri_mkdtemp_near(%s)",uri); + file=file_for_uri(uri); + path=g_file_get_path(file); + g_object_unref(file); + if (path) + { + tmppath=razor_file_default_mkdtemp_near(path,template,error); + g_free(path); + if (tmppath) + { + file=g_file_new_for_path(tmppath); + tmpuri=g_file_get_uri(file); + g_object_unref(file); + retval=strdup(tmpuri); + g_free(tmpuri); + } + else + retval=NULL; + } + else + { + razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED, + uri,"File is not local"); + retval=NULL; + } + return retval; +} + +struct uri_dir { + void *razor_file_default; + GFileEnumerator *enumerator; +}; + +void *uri_opendir(const char *uri,struct razor_error **error) +{ + GFile *file; + gchar *path; + struct uri_dir *dir; + GError *err=NULL; + g_message("uri_opendir(%s)",uri); + dir=g_new0(struct uri_dir,1); + file=file_for_uri(uri); + path=g_file_get_path(file); + if (path) + { + dir->razor_file_default=razor_file_default_opendir(path,error); + if (!dir->razor_file_default) + { + g_free(dir); + dir=NULL; + } + g_free(path); + } + else + { + dir->enumerator=g_file_enumerate_children(file, + G_FILE_ATTRIBUTE_STANDARD_NAME,G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL,&err); + if (!dir->enumerator) + { + g_free(dir); + dir=NULL; + plover_propagate_g_error(error,err); + } + } + g_object_unref(file); + return dir; +} + +char *uri_readdir(void *dp,struct razor_error **error) +{ + struct uri_dir *dir=dp; + char *name; + GError *err=NULL; + GFileInfo *info; + g_message("uri_readdir(%p)",dp); + if (dir->razor_file_default) + name=razor_file_default_readdir(dir->razor_file_default,error); + else + { + info=g_file_enumerator_next_file(dir->enumerator,NULL,&err); + if (!info) + { + name=NULL; + plover_propagate_g_error(error,err); + } + else + { + name=strdup(g_file_info_get_name(info)); + g_object_unref(info); + } + } + return name; +} + +int uri_closedir(void *dp,struct razor_error **error) +{ + struct uri_dir *dir=dp; + int retval; + GError *err=NULL; + g_message("uri_closedir(%p)",dp); + if (dir->razor_file_default) + retval=razor_file_default_closedir(dir->razor_file_default,error); + else + { + retval=g_file_enumerator_close(dir->enumerator,NULL,&err)?0:-1; + if (retval) + plover_propagate_g_error(error,err); + g_object_unref(dir->enumerator); + } + g_free(dir); + return retval; +} + +void plover__uri_handler_init(void) +{ + static gsize init=0; + struct razor_uri_vtable uri_vtable={0,}; + g_message("plover__uri_handler_init()"); + if (g_once_init_enter(&init)) + { + uri_vtable.structure_size=sizeof(uri_vtable); + uri_vtable.mkdir=uri_mkdir; + uri_vtable.unlink=uri_unlink; + uri_vtable.open=uri_open; + uri_vtable.move=uri_move; + uri_vtable.get_contents=uri_get_contents; + uri_vtable.free_contents=uri_free_contents; + uri_vtable.is_directory=uri_is_directory; + uri_vtable.mkdtemp_near=uri_mkdtemp_near; + uri_vtable.opendir=uri_opendir; + uri_vtable.readdir=uri_readdir; + uri_vtable.closedir=uri_closedir; + razor_uri_set_vtable(&uri_vtable); + g_once_init_leave(&init,1); + } +} diff -r 6b3034a884dc -r 43ffed8669ce plover/uri-handler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plover/uri-handler.h Wed Jun 22 17:04:28 2016 +0100 @@ -0,0 +1,10 @@ +#ifndef __URI_HANDLER_H__ +#define __URI_HANDLER_H__ + +G_BEGIN_DECLS + +void plover__uri_handler_init(void); + +G_END_DECLS + +#endif /* __URI_HANDLER_H__ */ diff -r 6b3034a884dc -r 43ffed8669ce tests/Makefile.am --- a/tests/Makefile.am Thu Jun 16 18:00:21 2016 +0100 +++ b/tests/Makefile.am Wed Jun 22 17:04:28 2016 +0100 @@ -54,10 +54,10 @@ razor-test-dir/var/lib/razor/system.rzdb: primary.xml.gz $(RM) -r razor-test-dir - $(RAZOR) --root=razor-test-dir init - $(RAZOR) --root=razor-test-dir \ + $(RAZOR) --root=file:razor-test-dir init + $(RAZOR) --root=file:razor-test-dir \ --url=file://localhost/`pwd`/yum-repo-test-dir import-yum - $(RAZOR) --root=razor-test-dir install zap zappy zappy2 zappy-tools + $(RAZOR) --root=file:razor-test-dir install zap zappy zappy2 zappy-tools endif diff -r 6b3034a884dc -r 43ffed8669ce tests/plover/Makefile.am --- a/tests/plover/Makefile.am Thu Jun 16 18:00:21 2016 +0100 +++ b/tests/plover/Makefile.am Wed Jun 22 17:04:28 2016 +0100 @@ -11,25 +11,25 @@ test_programs = test-import-yum test-package test-repository test-packageset \ test-transaction test-comps test-log test-util test-razor test-vector \ - test-exception-handler test-fileio + test-exception-handler test-uri-handler test_transaction_LDADD = $(LDADD) $(LUA_POSIX_LIBS) test_razor_LDADD = $(LDADD) $(LUA_POSIX_LIBS) -test_fileio_SOURCES = test-fileio.c test-fileio-gresource.c -test_fileio_DEPENDENCIES = test-fileio-gresource.h -test_fileio_LDADD = $(LDADD) $(LUA_POSIX_LIBS) +test_uri_handler_SOURCES = test-uri-handler.c test-uri-handler-gresource.c \ + test-uri-handler-gresource.h +test_uri_handler_LDADD = $(LDADD) $(LUA_POSIX_LIBS) -test-fileio-gresource.c: test-fileio.gresource.xml +test-uri-handler-gresource.c: test-uri-handler.gresource.xml $(AM_V_GEN)$(COMPILE_RESOURCES) --target=$@ --generate \ --sourcedir=../yum-repo-test-dir --manual-register \ - test-fileio.gresource.xml + test-uri-handler.gresource.xml -test-fileio-gresource.h: test-fileio.gresource.xml +test-uri-handler-gresource.h: test-uri-handler.gresource.xml $(AM_V_GEN)$(COMPILE_RESOURCES) --target=$@ --generate \ --sourcedir=../yum-repo-test-dir --manual-register \ - test-fileio.gresource.xml + test-uri-handler.gresource.xml -test-fileio.gresource.xml: +test-uri-handler.gresource.xml: $(AM_V_GEN)(cd ../yum-repo-test-dir; \ echo ''; \ echo ''; \ @@ -46,5 +46,7 @@ clean-local: rm -rf test-log-rotate razor-test-dir-* -CLEANFILES = test-fileio-gresource.c test-fileio-gresource.h \ - test-fileio.gresource.xml +BUILT_SOURCES = test-uri-handler-gresource.c test-uri-handler-gresource.h + +CLEANFILES = test-uri-handler-gresource.c test-uri-handler-gresource.h \ + test-uri-handler.gresource.xml diff -r 6b3034a884dc -r 43ffed8669ce tests/plover/test-fileio.c --- a/tests/plover/test-fileio.c Thu Jun 16 18:00:21 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2009, 2011, 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 -#include "config.h" -#include "plover/plover.h" -#include "test-fileio-gresource.h" - -LUALIB_API int luaopen_posix(lua_State *L); - -void test_resource(void) -{ - gchar *prefix,*root,*root_uri,*s; - int ch,changed; - struct comps *comps; - struct comps_group *group; - struct comps_requirement *pkg; - struct plover_vector *packages=NULL; - GError *error=NULL; - GFile *file; - test_fileio_register_resource(); - root=g_strdup("razor-test-dir-XXXXXX"); - g_assert(mkdtemp(root)); - file=g_file_new_for_path(root); - root_uri=g_file_get_uri(file); - g_object_unref(file); - g_setenv("RAZOR_ROOT",root_uri,TRUE); - g_free(root_uri); - comps=plover_comps_new_from_uri( - "resource:///uk/co/juiblex/project/plover/repodata/comps.xml"); - if (!comps) - { - perror("resource:///uk/co/juiblex/project/plover/repodata/comps.xml"); - exit(1); - } - prefix=plover_default_prefix_for_vendor(comps->vendor); - group=plover_comps_lookup_group(comps,"base"); - if (!group) - { - fprintf(stderr,"No base group found in comps.xml\n"); - exit(1); - } - packages=plover_vector_new(); - do - { - changed=0; - for(pkg=group->packages;pkg;pkg=pkg->next) - { - if (plover_vector_contains(packages,pkg->name)) - continue; - if (pkg->type==COMPS_REQUIREMENT_DEFAULT || - pkg->type==COMPS_REQUIREMENT_MANDATORY || - pkg->type==COMPS_REQUIREMENT_CONDITIONAL && (!pkg->requires || - plover_vector_contains(packages,pkg->requires))) - { - changed++; - plover_vector_append(packages,pkg->name); - } - } - } while(changed); - plover_comps_free(comps); - if (!packages->len) - { - fprintf(stderr,"No packages to install\n"); - exit(1); - } - if (!plover_install_uri("resource:///uk/co/juiblex/project/plover",prefix, - packages->strings,&error)) - { - fprintf(stderr,"%s\n",error->message); - g_error_free(error); - exit(1); - } - plover_vector_free(packages); - g_free(prefix); - g_unsetenv("RAZOR_ROOT"); - test_fileio_unregister_resource(); - s=g_build_filename(root,"usr/bin/zsh",NULL); - g_free(root); - if (!g_file_test(s,G_FILE_TEST_EXISTS)) - g_error("%s: Missing file",s); - g_free(s); -} - -int main(int argc,char **argv) -{ - int retval; - razor_set_lua_loader("posix",(void (*)())luaopen_posix); - g_test_init(&argc,&argv,NULL); - g_test_bug_base("mailto:ali@juiblex.co.uk"); - g_test_add_func("/fileio/resource",test_resource); - retval=g_test_run(); - return retval; -} diff -r 6b3034a884dc -r 43ffed8669ce tests/plover/test-log.c --- a/tests/plover/test-log.c Thu Jun 16 18:00:21 2016 +0100 +++ b/tests/plover/test-log.c Wed Jun 22 17:04:28 2016 +0100 @@ -165,7 +165,7 @@ system("rm -rf test-log-rotate"); g_assert(mkdir("test-log-rotate",0777)==0); cwd=g_get_current_dir(); - s=g_strconcat(cwd,"/",NULL); + s=g_strconcat("file:",cwd,"/",NULL); g_free(cwd); g_setenv("RAZOR_ROOT",s,TRUE); g_free(s); diff -r 6b3034a884dc -r 43ffed8669ce tests/plover/test-package.c --- a/tests/plover/test-package.c Thu Jun 16 18:00:21 2016 +0100 +++ b/tests/plover/test-package.c Wed Jun 22 17:04:28 2016 +0100 @@ -123,7 +123,7 @@ struct razor_rpm *rpm; PloverPackage *package=NULL; struct razor_error *err=NULL; - gchar *filename; + gchar *uri; if (test_set) { razor_set_unref(test_set); @@ -135,12 +135,12 @@ * razor_importer_add_rpm() doesn't support prefixes so we have * to do it the really hard way. */ - filename=g_strconcat("../yum-repo-test-dir/rpms/",name,"-",version, + uri=g_strconcat("file:../yum-repo-test-dir/rpms/",name,"-",version, ".noarch.rpm",NULL); - rpm=razor_rpm_open(filename,&err); + rpm=razor_rpm_open(uri,&err); if (!rpm) - g_error("%s: %s",filename,razor_error_get_msg(err)); - g_free(filename); + g_error("%s: %s",uri,razor_error_get_msg(err)); + g_free(uri); if (import_rpm(rpm)) package=plover_package_new(test_set,test_pkg); else diff -r 6b3034a884dc -r 43ffed8669ce tests/plover/test-uri-handler.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/plover/test-uri-handler.c Wed Jun 22 17:04:28 2016 +0100 @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2009, 2011, 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 +#include "config.h" +#include "plover/plover.h" +#include "plover/uri-handler.h" +#include "test-uri-handler-gresource.h" + +LUALIB_API int luaopen_posix(lua_State *L); + +void test_resource(void) +{ + gchar *prefix,*root,*root_uri,*s; + int ch,changed; + struct comps *comps; + struct comps_group *group; + struct comps_requirement *pkg; + struct plover_vector *packages=NULL; + GError *error=NULL; + GFile *file; + test_uri_handler_register_resource(); + root=g_strdup("razor-test-dir-XXXXXX"); + g_assert(mkdtemp(root)); + file=g_file_new_for_path(root); + root_uri=g_file_get_uri(file); + g_object_unref(file); + g_setenv("RAZOR_ROOT",root_uri,TRUE); + g_free(root_uri); + comps=plover_comps_new_from_uri( + "resource:///uk/co/juiblex/project/plover/repodata/comps.xml"); + if (!comps) + { + perror("resource:///uk/co/juiblex/project/plover/repodata/comps.xml"); + exit(1); + } + prefix=plover_default_prefix_for_vendor(comps->vendor); + group=plover_comps_lookup_group(comps,"base"); + if (!group) + { + fprintf(stderr,"No base group found in comps.xml\n"); + exit(1); + } + packages=plover_vector_new(); + do + { + changed=0; + for(pkg=group->packages;pkg;pkg=pkg->next) + { + if (plover_vector_contains(packages,pkg->name)) + continue; + if (pkg->type==COMPS_REQUIREMENT_DEFAULT || + pkg->type==COMPS_REQUIREMENT_MANDATORY || + pkg->type==COMPS_REQUIREMENT_CONDITIONAL && (!pkg->requires || + plover_vector_contains(packages,pkg->requires))) + { + changed++; + plover_vector_append(packages,pkg->name); + } + } + } while(changed); + plover_comps_free(comps); + if (!packages->len) + { + fprintf(stderr,"No packages to install\n"); + exit(1); + } + if (!plover_install_uri("resource:///uk/co/juiblex/project/plover",prefix, + packages->strings,&error)) + { + fprintf(stderr,"%s\n",error->message); + g_error_free(error); + exit(1); + } + plover_vector_free(packages); + g_free(prefix); + g_unsetenv("RAZOR_ROOT"); + test_uri_handler_unregister_resource(); + s=g_build_filename(root,"usr/bin/zsh",NULL); + g_free(root); + if (!g_file_test(s,G_FILE_TEST_EXISTS)) + g_error("%s: Missing file",s); + g_free(s); +} + +int main(int argc,char **argv) +{ + int retval; + razor_set_lua_loader("posix",(void (*)())luaopen_posix); + g_test_init(&argc,&argv,NULL); + g_test_bug_base("mailto:ali@juiblex.co.uk"); + g_test_add_func("/uri-handler/resource",test_resource); + retval=g_test_run(); + return retval; +}