Port to razor 0.6.3.60
authorJ. Ali Harlow <ali@juiblex.co.uk>
Wed Jun 22 17:04:28 2016 +0100 (2016-06-22)
changeset 4443ffed8669ce
parent 43 6b3034a884dc
child 45 a166277bc796
Port to razor 0.6.3.60
plover-gtk/transactionhelper.c
plover/Makefile.am
plover/comps.c
plover/fileio.c
plover/fileio.h
plover/import-yum.c
plover/log.c
plover/package.c
plover/packageset.c
plover/razor.c
plover/repository.c
plover/uri-handler.c
plover/uri-handler.h
tests/Makefile.am
tests/plover/Makefile.am
tests/plover/test-fileio.c
tests/plover/test-log.c
tests/plover/test-package.c
tests/plover/test-uri-handler.c
     1.1 --- a/plover-gtk/transactionhelper.c	Thu Jun 16 18:00:21 2016 +0100
     1.2 +++ b/plover-gtk/transactionhelper.c	Wed Jun 22 17:04:28 2016 +0100
     1.3 @@ -23,6 +23,7 @@
     1.4  #include <plover/plover.h>
     1.5  #include <plover/transaction.h>
     1.6  #include <plover-gtk/transactionhelper.h>
     1.7 +#include "plover/uri-handler.h"
     1.8  
     1.9  /*
    1.10   * A PloverTransactionHelper uses a GtkAssistant to help a user run a
    1.11 @@ -95,7 +96,7 @@
    1.12  static void
    1.13    plover_transaction_helper_class_init(PloverTransactionHelperClass *klass)
    1.14  {
    1.15 -    plover__file_io_init();
    1.16 +    plover__uri_handler_init();
    1.17      GObjectClass *gobject_class=G_OBJECT_CLASS(klass);
    1.18      gobject_class->finalize=
    1.19        (void (*)(GObject *))plover_transaction_helper_finalize;
     2.1 --- a/plover/Makefile.am	Thu Jun 16 18:00:21 2016 +0100
     2.2 +++ b/plover/Makefile.am	Wed Jun 22 17:04:28 2016 +0100
     2.3 @@ -10,7 +10,7 @@
     2.4  lib_LTLIBRARIES=libplover.la
     2.5  libplover_la_SOURCES=$(pkginclude_HEADERS) util.c import-yum.c razor.c comps.c \
     2.6  	log.c vector.c transaction.c package.c packageset.c repository.c \
     2.7 -	fileio.c fileio.h exception-handler.cpp
     2.8 +	uri-handler.c uri-handler.h exception-handler.cpp
     2.9  
    2.10  pkgconfigdir=$(libdir)/pkgconfig
    2.11  pkgconfig_DATA=plover.pc
     3.1 --- a/plover/comps.c	Thu Jun 16 18:00:21 2016 +0100
     3.2 +++ b/plover/comps.c	Wed Jun 22 17:04:28 2016 +0100
     3.3 @@ -24,6 +24,7 @@
     3.4  #include <expat.h>
     3.5  #include <assert.h>
     3.6  #include "plover/plover.h"
     3.7 +#include "plover/uri-handler.h"
     3.8  
     3.9  /* Parse a comps.xml package group file. */
    3.10  
    3.11 @@ -381,7 +382,7 @@
    3.12      GFileInputStream *stream;
    3.13      XML_ParsingStatus status;
    3.14      struct comps *comps;
    3.15 -    plover__file_io_init();
    3.16 +    plover__uri_handler_init();
    3.17      file=g_file_new_for_uri(uri);
    3.18      stream=g_file_read(file,NULL,NULL);
    3.19      g_object_unref(file);
     4.1 --- a/plover/fileio.c	Thu Jun 16 18:00:21 2016 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,417 +0,0 @@
     4.4 -/*
     4.5 - * Copyright (C) 2016  J. Ali Harlow <ali@juiblex.co.uk>
     4.6 - *
     4.7 - * This program is free software; you can redistribute it and/or modify
     4.8 - * it under the terms of the GNU General Public License as published by
     4.9 - * the Free Software Foundation; either version 2 of the License, or
    4.10 - * (at your option) any later version.
    4.11 - *
    4.12 - * This program is distributed in the hope that it will be useful,
    4.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 - * GNU General Public License for more details.
    4.16 - *
    4.17 - * You should have received a copy of the GNU General Public License along
    4.18 - * with this program; if not, write to the Free Software Foundation, Inc.,
    4.19 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    4.20 - */
    4.21 -
    4.22 -#include <stdlib.h>
    4.23 -#include <string.h>
    4.24 -#include <errno.h>
    4.25 -#include <razor.h>
    4.26 -#include <glib.h>
    4.27 -#include <gio/gio.h>
    4.28 -#include "config.h"
    4.29 -#include "plover/plover.h"
    4.30 -
    4.31 -static GList *open_razor_files;
    4.32 -
    4.33 -static gboolean has_valid_scheme(const char *uri)
    4.34 -{
    4.35 -    /*
    4.36 -     * RFC 2396 defines valid schemes as:
    4.37 -     * scheme = alpha *( alpha | digit | "+" | "-" | "." )
    4.38 -     */
    4.39 -    const char *s;
    4.40 -    if (!g_ascii_isalpha(*uri))
    4.41 -	return FALSE;
    4.42 -    for(s=uri+1;;s++)
    4.43 -	if (*s==':')
    4.44 -	    return TRUE;
    4.45 -	else if (!g_ascii_isalnum(*s) && *s!='+' && *s!='-' && *s!='.')
    4.46 -	    return FALSE;
    4.47 -}
    4.48 -
    4.49 -static GFile *file_for_uri(const char *uri)
    4.50 -{
    4.51 -    GFile *file;
    4.52 -    if (!has_valid_scheme(uri))
    4.53 -    {
    4.54 -	g_warning("%s: Not a valid URI",uri);
    4.55 -	file=g_file_new_for_path(uri);
    4.56 -    }
    4.57 -    else
    4.58 -    {
    4.59 -	if (strstr(uri+1,"file:/"))
    4.60 -	    g_warning("%s: Implausible URI",uri);
    4.61 -	file=g_file_new_for_uri(uri);
    4.62 -    }
    4.63 -    return file;
    4.64 -}
    4.65 -
    4.66 -int file_mkdir(const char *uri,mode_t mode,struct razor_error **error)
    4.67 -{
    4.68 -    GFile *file;
    4.69 -    GFileInfo *info;
    4.70 -    gchar *path;
    4.71 -    int retval;
    4.72 -    GError *err=NULL;
    4.73 -    g_message("file_mkdir(%s)",uri);
    4.74 -    file=file_for_uri(uri);
    4.75 -    path=g_file_get_path(file);
    4.76 -    if (path)
    4.77 -    {
    4.78 -	retval=razor_file_default_mkdir(path,mode,error);
    4.79 -	g_free(path);
    4.80 -    }
    4.81 -    else if (!g_file_make_directory(file,NULL,&err))
    4.82 -    {
    4.83 -	retval=-1;
    4.84 -	if (g_error_matches(err,G_IO_ERROR,G_IO_ERROR_EXISTS))
    4.85 -	{
    4.86 -	    info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
    4.87 -	      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,NULL);
    4.88 -	    if (info)
    4.89 -	    {
    4.90 -		g_clear_error(&err);
    4.91 -		if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY)
    4.92 -		    retval=0;
    4.93 -		else
    4.94 -		    razor_set_error(error,RAZOR_POSIX_ERROR,EEXIST,uri,
    4.95 -		      "Not a directory");
    4.96 -		g_object_unref(info);
    4.97 -	    }
    4.98 -	}
    4.99 -	if (err)
   4.100 -	    plover_propagate_g_error(error,err);
   4.101 -    }
   4.102 -    else
   4.103 -	retval=0;
   4.104 -    g_object_unref(file);
   4.105 -    return retval;
   4.106 -}
   4.107 -
   4.108 -int file_unlink(const char *uri,struct razor_error **error)
   4.109 -{
   4.110 -    GFile *file;
   4.111 -    gchar *path;
   4.112 -    int retval;
   4.113 -    GError *err=NULL;
   4.114 -    g_message("file_unlink(%s)",uri);
   4.115 -    file=file_for_uri(uri);
   4.116 -    path=g_file_get_path(file);
   4.117 -    if (path)
   4.118 -    {
   4.119 -	retval=razor_file_default_unlink(path,error);
   4.120 -	g_free(path);
   4.121 -    }
   4.122 -    else if (!g_file_delete(file,NULL,&err))
   4.123 -    {
   4.124 -	plover_propagate_g_error(error,err);
   4.125 -	retval=-1;
   4.126 -    }
   4.127 -    else
   4.128 -	retval=0;
   4.129 -    g_object_unref(file);
   4.130 -    return retval;
   4.131 -}
   4.132 -
   4.133 -int file_open(const char *uri,int flags,mode_t mode,struct razor_error **error)
   4.134 -{
   4.135 -    GFile *file;
   4.136 -    gchar *path;
   4.137 -    int retval;
   4.138 -    GError *err=NULL;
   4.139 -    g_message("file_open(%s)",uri);
   4.140 -    file=file_for_uri(uri);
   4.141 -    path=g_file_get_path(file);
   4.142 -    if (path)
   4.143 -    {
   4.144 -	retval=razor_file_default_open(path,flags,mode,error);
   4.145 -	g_free(path);
   4.146 -    }
   4.147 -    else
   4.148 -    {
   4.149 -	razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED,
   4.150 -	  uri,"File is not local");
   4.151 -	retval=-1;
   4.152 -    }
   4.153 -    g_object_unref(file);
   4.154 -    return retval;
   4.155 -}
   4.156 -
   4.157 -int file_move(const char *src_uri,const char *dst_uri,
   4.158 -  struct razor_error **error)
   4.159 -{
   4.160 -    GFile *src,*dst;
   4.161 -    gchar *src_path,*dst_path;
   4.162 -    int retval;
   4.163 -    GError *err=NULL;
   4.164 -    g_message("file_move(%s,%s)",src_uri,dst_uri);
   4.165 -    src=file_for_uri(src_uri);
   4.166 -    dst=file_for_uri(dst_uri);
   4.167 -    src_path=g_file_get_path(src);
   4.168 -    dst_path=g_file_get_path(dst);
   4.169 -    if (src_path && dst_path)
   4.170 -	retval=razor_file_default_move(src_path,dst_path,error);
   4.171 -    else if (!g_file_move(src,dst,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&err))
   4.172 -    {
   4.173 -	plover_propagate_g_error(error,err);
   4.174 -	retval=-1;
   4.175 -    }
   4.176 -    else
   4.177 -	retval=0;
   4.178 -    g_free(src_path);
   4.179 -    g_free(dst_path);
   4.180 -    g_object_unref(src);
   4.181 -    g_object_unref(dst);
   4.182 -    return retval;
   4.183 -}
   4.184 -
   4.185 -static void *file_get_contents(const char *uri,size_t *length,int private,
   4.186 -  struct razor_error **error)
   4.187 -{
   4.188 -    GFile *file;
   4.189 -    gchar *path;
   4.190 -    void *addr;
   4.191 -    char *contents;
   4.192 -    gsize len;
   4.193 -    GError *err=NULL;
   4.194 -    g_message("file_get_contents(%s)",uri);
   4.195 -    file=file_for_uri(uri);
   4.196 -    path=g_file_get_path(file);
   4.197 -    if (path)
   4.198 -    {
   4.199 -	g_object_unref(file);
   4.200 -	addr=razor_file_default_get_contents(path,length,private,error);
   4.201 -	if (addr)
   4.202 -	    open_razor_files=g_list_prepend(open_razor_files,addr);
   4.203 -	g_free(path);
   4.204 -    }
   4.205 -    else if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err))
   4.206 -    {
   4.207 -	plover_propagate_g_error(error,err);
   4.208 -	g_object_unref(file);
   4.209 -	addr=NULL;
   4.210 -    }
   4.211 -    else
   4.212 -    {
   4.213 -	g_object_unref(file);
   4.214 -	addr=contents;
   4.215 -	if (length)
   4.216 -	    *length=len;
   4.217 -    }
   4.218 -    return addr;
   4.219 -}
   4.220 -
   4.221 -static int file_free_contents(void *addr,size_t length)
   4.222 -{
   4.223 -    int retval;
   4.224 -    GList *lnk;
   4.225 -    g_message("file_free_contents(%p)",addr);
   4.226 -    lnk=g_list_find(open_razor_files,addr);
   4.227 -    if (lnk)
   4.228 -    {
   4.229 -	open_razor_files=g_list_delete_link(open_razor_files,lnk);
   4.230 -	retval=razor_file_default_free_contents(addr,length);
   4.231 -    }
   4.232 -    else
   4.233 -    {
   4.234 -	g_free(addr);
   4.235 -	retval=0;
   4.236 -    }
   4.237 -    return retval;
   4.238 -}
   4.239 -
   4.240 -int file_is_directory(const char *uri,struct razor_error **error)
   4.241 -{
   4.242 -    GFile *file;
   4.243 -    GFileInfo *info;
   4.244 -    gchar *path;
   4.245 -    int retval;
   4.246 -    GError *err=NULL;
   4.247 -    g_message("file_is_directory(%s)",uri);
   4.248 -    file=file_for_uri(uri);
   4.249 -    path=g_file_get_path(file);
   4.250 -    if (path)
   4.251 -    {
   4.252 -	retval=razor_file_default_is_directory(path,error);
   4.253 -	g_free(path);
   4.254 -    }
   4.255 -    else
   4.256 -    {
   4.257 -	info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
   4.258 -	  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err);
   4.259 -	if (info)
   4.260 -	{
   4.261 -	    if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY)
   4.262 -		retval=1;
   4.263 -	    else
   4.264 -		retval=0;
   4.265 -	    g_object_unref(info);
   4.266 -	}
   4.267 -	else
   4.268 -	{
   4.269 -	    retval=-1;
   4.270 -	    plover_propagate_g_error(error,err);
   4.271 -	}
   4.272 -    }
   4.273 -    g_object_unref(file);
   4.274 -    return retval;
   4.275 -}
   4.276 -
   4.277 -char *file_mkdtemp_near(const char *uri,const char *template,
   4.278 -  struct razor_error **error)
   4.279 -{
   4.280 -    GFile *file;
   4.281 -    gchar *path,*tmpuri;
   4.282 -    char *tmppath,*retval;
   4.283 -    GError *err=NULL;
   4.284 -    g_message("file_mkdtemp_near(%s)",uri);
   4.285 -    file=file_for_uri(uri);
   4.286 -    path=g_file_get_path(file);
   4.287 -    g_object_unref(file);
   4.288 -    if (path)
   4.289 -    {
   4.290 -	tmppath=razor_file_default_mkdtemp_near(path,template,error);
   4.291 -	g_free(path);
   4.292 -	if (tmppath)
   4.293 -	{
   4.294 -	    file=g_file_new_for_path(tmppath);
   4.295 -	    tmpuri=g_file_get_uri(file);
   4.296 -	    g_object_unref(file);
   4.297 -	    retval=strdup(tmpuri);
   4.298 -	    g_free(tmpuri);
   4.299 -	}
   4.300 -	else
   4.301 -	    retval=NULL;
   4.302 -    }
   4.303 -    else
   4.304 -    {
   4.305 -	razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED,
   4.306 -	  uri,"File is not local");
   4.307 -	retval=NULL;
   4.308 -    }
   4.309 -    return retval;
   4.310 -}
   4.311 -
   4.312 -struct file_dir {
   4.313 -    void *razor_file_default;
   4.314 -    GFileEnumerator *enumerator;
   4.315 -};
   4.316 -
   4.317 -void *file_opendir(const char *uri,struct razor_error **error)
   4.318 -{
   4.319 -    GFile *file;
   4.320 -    gchar *path;
   4.321 -    struct file_dir *dir;
   4.322 -    GError *err=NULL;
   4.323 -    g_message("file_opendir(%s)",uri);
   4.324 -    dir=g_new0(struct file_dir,1);
   4.325 -    file=file_for_uri(uri);
   4.326 -    path=g_file_get_path(file);
   4.327 -    if (path)
   4.328 -    {
   4.329 -	dir->razor_file_default=razor_file_default_opendir(path,error);
   4.330 -	if (!dir->razor_file_default)
   4.331 -	{
   4.332 -	    g_free(dir);
   4.333 -	    dir=NULL;
   4.334 -	}
   4.335 -	g_free(path);
   4.336 -    }
   4.337 -    else
   4.338 -    {
   4.339 -	dir->enumerator=g_file_enumerate_children(file,
   4.340 -	  G_FILE_ATTRIBUTE_STANDARD_NAME,G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
   4.341 -	  NULL,&err);
   4.342 -	if (!dir->enumerator)
   4.343 -	{
   4.344 -	    g_free(dir);
   4.345 -	    dir=NULL;
   4.346 -	    plover_propagate_g_error(error,err);
   4.347 -	}
   4.348 -    }
   4.349 -    g_object_unref(file);
   4.350 -    return dir;
   4.351 -}
   4.352 -
   4.353 -char *file_readdir(void *dp,struct razor_error **error)
   4.354 -{
   4.355 -    struct file_dir *dir=dp;
   4.356 -    char *name;
   4.357 -    GError *err=NULL;
   4.358 -    GFileInfo *info;
   4.359 -    g_message("file_readdir(%p)",dp);
   4.360 -    if (dir->razor_file_default)
   4.361 -	name=razor_file_default_readdir(dir->razor_file_default,error);
   4.362 -    else
   4.363 -    {
   4.364 -	info=g_file_enumerator_next_file(dir->enumerator,NULL,&err);
   4.365 -	if (!info)
   4.366 -	{
   4.367 -	    name=NULL;
   4.368 -	    plover_propagate_g_error(error,err);
   4.369 -	}
   4.370 -	else
   4.371 -	{
   4.372 -	    name=strdup(g_file_info_get_name(info));
   4.373 -	    g_object_unref(info);
   4.374 -	}
   4.375 -    }
   4.376 -    return name;
   4.377 -}
   4.378 -
   4.379 -int file_closedir(void *dp,struct razor_error **error)
   4.380 -{
   4.381 -    struct file_dir *dir=dp;
   4.382 -    int retval;
   4.383 -    GError *err=NULL;
   4.384 -    g_message("file_closedir(%p)",dp);
   4.385 -    if (dir->razor_file_default)
   4.386 -	retval=razor_file_default_closedir(dir->razor_file_default,error);
   4.387 -    else
   4.388 -    {
   4.389 -	retval=g_file_enumerator_close(dir->enumerator,NULL,&err)?0:-1;
   4.390 -	if (retval)
   4.391 -	    plover_propagate_g_error(error,err);
   4.392 -	g_object_unref(dir->enumerator);
   4.393 -    }
   4.394 -    g_free(dir);
   4.395 -    return retval;
   4.396 -}
   4.397 -
   4.398 -void plover__file_io_init(void)
   4.399 -{
   4.400 -    static gsize init=0;
   4.401 -    struct razor_file_vtable file_vtable={0,};
   4.402 -    g_message("plover__file_io_init()");
   4.403 -    if (g_once_init_enter(&init))
   4.404 -    {
   4.405 -	file_vtable.structure_size=sizeof(file_vtable);
   4.406 -	file_vtable.mkdir=file_mkdir;
   4.407 -	file_vtable.unlink=file_unlink;
   4.408 -	file_vtable.open=file_open;
   4.409 -	file_vtable.move=file_move;
   4.410 -	file_vtable.get_contents=file_get_contents;
   4.411 -	file_vtable.free_contents=file_free_contents;
   4.412 -	file_vtable.is_directory=file_is_directory;
   4.413 -	file_vtable.mkdtemp_near=file_mkdtemp_near;
   4.414 -	file_vtable.opendir=file_opendir;
   4.415 -	file_vtable.readdir=file_readdir;
   4.416 -	file_vtable.closedir=file_closedir;
   4.417 -	razor_file_set_vtable(&file_vtable);
   4.418 -	g_once_init_leave(&init,1);
   4.419 -    }
   4.420 -}
     5.1 --- a/plover/fileio.h	Thu Jun 16 18:00:21 2016 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,10 +0,0 @@
     5.4 -#ifndef __FILEIO_H__
     5.5 -#define __FILEIO_H__
     5.6 -
     5.7 -G_BEGIN_DECLS
     5.8 -
     5.9 -void plover__file_io_init(void);
    5.10 -
    5.11 -G_END_DECLS
    5.12 -
    5.13 -#endif /* __FILEIO_H__ */
     6.1 --- a/plover/import-yum.c	Thu Jun 16 18:00:21 2016 +0100
     6.2 +++ b/plover/import-yum.c	Wed Jun 22 17:04:28 2016 +0100
     6.3 @@ -32,7 +32,8 @@
     6.4  #include <expat.h>
     6.5  #include <zlib.h>
     6.6  #include <razor.h>
     6.7 -#include "plover.h"
     6.8 +#include "plover/plover.h"
     6.9 +#include "plover/uri-handler.h"
    6.10  
    6.11  /* Import a yum filelist as a razor package set. */
    6.12  
    6.13 @@ -320,7 +321,7 @@
    6.14      GZlibDecompressor *decompressor;
    6.15      XML_ParsingStatus status;
    6.16      struct razor_set *set;
    6.17 -    plover__file_io_init();
    6.18 +    plover__uri_handler_init();
    6.19      ctx.importer=razor_importer_create();
    6.20      ctx.state=YUM_STATE_BEGIN;
    6.21      ctx.primary_parser=XML_ParserCreate(NULL);
     7.1 --- a/plover/log.c	Thu Jun 16 18:00:21 2016 +0100
     7.2 +++ b/plover/log.c	Wed Jun 22 17:04:28 2016 +0100
     7.3 @@ -287,19 +287,36 @@
     7.4  {
     7.5      int retval;
     7.6      char *root;
     7.7 -    gchar *filename;
     7.8 +    gchar *s,*filename;
     7.9      struct stat sb;
    7.10      time_t t;
    7.11      struct tm today,modified;
    7.12      struct razor_atomic *atomic;
    7.13 +    struct razor_error *error=NULL;
    7.14 +    GFile *base_file,*file;
    7.15      FILE *fp;
    7.16      root=getenv("RAZOR_ROOT");
    7.17      if (root)
    7.18 -	filename=g_strconcat(root,path,NULL);
    7.19 +    {
    7.20 +	base_file=g_file_new_for_uri(root);
    7.21 +	file=g_file_resolve_relative_path(base_file,path);
    7.22 +	g_object_unref(base_file);
    7.23 +	filename=g_file_get_path(file);
    7.24 +	if (!filename)
    7.25 +	{
    7.26 +	    fprintf(stderr,"%s: Can't get local path\n",g_file_get_uri(file));
    7.27 +	    g_object_unref(file);
    7.28 +	    return -1;
    7.29 +	}
    7.30 +	g_object_unref(file);
    7.31 +    }
    7.32      else
    7.33  	filename=g_strdup(path);
    7.34      atomic=razor_atomic_open("Open log");
    7.35 -    razor_atomic_make_dirs(atomic,"",filename);
    7.36 +    if (root)
    7.37 +	razor_atomic_make_dirs(atomic,root,path);
    7.38 +    else
    7.39 +	razor_atomic_make_dirs(atomic,"file:",path);
    7.40      retval=razor_atomic_commit(atomic);
    7.41      if (retval)
    7.42  	fprintf(stderr,"Can't open log: %s\n",
    7.43 @@ -314,8 +331,7 @@
    7.44      {
    7.45  	if (errno!=ENOENT)
    7.46  	{
    7.47 -	    fprintf(stderr,"Can't open log: ");
    7.48 -	    perror(filename);
    7.49 +	    perror("Can't open log");
    7.50  	    g_free(filename);
    7.51  	    return -1;
    7.52  	}
     8.1 --- a/plover/package.c	Thu Jun 16 18:00:21 2016 +0100
     8.2 +++ b/plover/package.c	Wed Jun 22 17:04:28 2016 +0100
     8.3 @@ -22,6 +22,7 @@
     8.4  #include <glib-object.h>
     8.5  #include <razor.h>
     8.6  #include "plover/package.h"
     8.7 +#include "plover/uri-handler.h"
     8.8  
     8.9  G_DEFINE_TYPE(PloverPackage,plover_package,G_TYPE_OBJECT);
    8.10  
     9.1 --- a/plover/packageset.c	Thu Jun 16 18:00:21 2016 +0100
     9.2 +++ b/plover/packageset.c	Wed Jun 22 17:04:28 2016 +0100
     9.3 @@ -27,6 +27,7 @@
     9.4  #include "plover/plover.h"
     9.5  #include "plover/package.h"
     9.6  #include "plover/packageset.h"
     9.7 +#include "plover/uri-handler.h"
     9.8  
     9.9  G_DEFINE_TYPE(PloverPackageSet,plover_package_set,G_TYPE_OBJECT);
    9.10  
    9.11 @@ -85,7 +86,7 @@
    9.12  
    9.13  static void plover_package_set_class_init(PloverPackageSetClass *klass)
    9.14  {
    9.15 -    plover__file_io_init();
    9.16 +    plover__uri_handler_init();
    9.17      GObjectClass *oclass=G_OBJECT_CLASS(klass);
    9.18      oclass->finalize=plover_package_set_finalize;
    9.19      oclass->dispose=plover_package_set_dispose;
    9.20 @@ -373,7 +374,7 @@
    9.21      struct razor_error *tmp_error=NULL;
    9.22      GFile *file;
    9.23      gchar *uri;
    9.24 -    plover__file_io_init();
    9.25 +    plover__uri_handler_init();
    9.26      importer=razor_importer_create();
    9.27      for(i=0;filenames[i];i++)
    9.28      {
    10.1 --- a/plover/razor.c	Thu Jun 16 18:00:21 2016 +0100
    10.2 +++ b/plover/razor.c	Wed Jun 22 17:04:28 2016 +0100
    10.3 @@ -30,6 +30,7 @@
    10.4  #include "config.h"
    10.5  #include "plover/plover.h"
    10.6  #include "plover/transaction.h"
    10.7 +#include "plover/uri-handler.h"
    10.8  
    10.9  static char *rpm_filename(const char *name,const char *version,const char *arch)
   10.10  {
   10.11 @@ -63,7 +64,7 @@
   10.12      PloverPackage *package;
   10.13      GFile *file;
   10.14      gchar *uri;
   10.15 -    plover__file_io_init();
   10.16 +    plover__uri_handler_init();
   10.17      file=g_file_new_for_path(*install_root?install_root:"/");
   10.18      uri=g_file_get_uri(file);
   10.19      g_object_unref(file);
   10.20 @@ -271,7 +272,7 @@
   10.21      struct razor_package *package;
   10.22      struct razor_package_iterator *pi;
   10.23      struct razor_file_iterator *fi;
   10.24 -    plover__file_io_init();
   10.25 +    plover__uri_handler_init();
   10.26      len=strlen(prefix);
   10.27      while(len && prefix[len-1]=='/')
   10.28  	len--;
    11.1 --- a/plover/repository.c	Thu Jun 16 18:00:21 2016 +0100
    11.2 +++ b/plover/repository.c	Wed Jun 22 17:04:28 2016 +0100
    11.3 @@ -23,6 +23,7 @@
    11.4  #include <razor.h>
    11.5  #include <plover/plover.h>
    11.6  #include <plover/repository.h>
    11.7 +#include "plover/uri-handler.h"
    11.8  
    11.9  G_DEFINE_TYPE(PloverRepository,plover_repository,G_TYPE_OBJECT);
   11.10  
   11.11 @@ -54,7 +55,7 @@
   11.12  
   11.13  static void plover_repository_class_init(PloverRepositoryClass *klass)
   11.14  {
   11.15 -    plover__file_io_init();
   11.16 +    plover__uri_handler_init();
   11.17      GObjectClass *oclass=G_OBJECT_CLASS(klass);
   11.18      oclass->finalize=plover_repository_finalize;
   11.19      oclass->dispose=plover_repository_dispose;
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/plover/uri-handler.c	Wed Jun 22 17:04:28 2016 +0100
    12.3 @@ -0,0 +1,418 @@
    12.4 +/*
    12.5 + * Copyright (C) 2016  J. Ali Harlow <ali@juiblex.co.uk>
    12.6 + *
    12.7 + * This program is free software; you can redistribute it and/or modify
    12.8 + * it under the terms of the GNU General Public License as published by
    12.9 + * the Free Software Foundation; either version 2 of the License, or
   12.10 + * (at your option) any later version.
   12.11 + *
   12.12 + * This program is distributed in the hope that it will be useful,
   12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 + * GNU General Public License for more details.
   12.16 + *
   12.17 + * You should have received a copy of the GNU General Public License along
   12.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
   12.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   12.20 + */
   12.21 +
   12.22 +#include <stdlib.h>
   12.23 +#include <string.h>
   12.24 +#include <errno.h>
   12.25 +#include <razor.h>
   12.26 +#include <glib.h>
   12.27 +#include <gio/gio.h>
   12.28 +#include "config.h"
   12.29 +#include "plover/plover.h"
   12.30 +#include "uri-handler.h"
   12.31 +
   12.32 +static GList *open_razor_files;
   12.33 +
   12.34 +static gboolean has_valid_scheme(const char *uri)
   12.35 +{
   12.36 +    /*
   12.37 +     * RFC 2396 defines valid schemes as:
   12.38 +     * scheme = alpha *( alpha | digit | "+" | "-" | "." )
   12.39 +     */
   12.40 +    const char *s;
   12.41 +    if (!g_ascii_isalpha(*uri))
   12.42 +	return FALSE;
   12.43 +    for(s=uri+1;;s++)
   12.44 +	if (*s==':')
   12.45 +	    return TRUE;
   12.46 +	else if (!g_ascii_isalnum(*s) && *s!='+' && *s!='-' && *s!='.')
   12.47 +	    return FALSE;
   12.48 +}
   12.49 +
   12.50 +static GFile *file_for_uri(const char *uri)
   12.51 +{
   12.52 +    GFile *file;
   12.53 +    if (!has_valid_scheme(uri))
   12.54 +    {
   12.55 +	g_warning("%s: Not a valid URI",uri);
   12.56 +	file=g_file_new_for_path(uri);
   12.57 +    }
   12.58 +    else
   12.59 +    {
   12.60 +	if (strstr(uri+1,"file:/"))
   12.61 +	    g_warning("%s: Implausible URI",uri);
   12.62 +	file=g_file_new_for_uri(uri);
   12.63 +    }
   12.64 +    return file;
   12.65 +}
   12.66 +
   12.67 +int uri_mkdir(const char *uri,mode_t mode,struct razor_error **error)
   12.68 +{
   12.69 +    GFile *file;
   12.70 +    GFileInfo *info;
   12.71 +    gchar *path;
   12.72 +    int retval;
   12.73 +    GError *err=NULL;
   12.74 +    g_message("uri_mkdir(%s)",uri);
   12.75 +    file=file_for_uri(uri);
   12.76 +    path=g_file_get_path(file);
   12.77 +    if (path)
   12.78 +    {
   12.79 +	retval=razor_file_default_mkdir(path,mode,error);
   12.80 +	g_free(path);
   12.81 +    }
   12.82 +    else if (!g_file_make_directory(file,NULL,&err))
   12.83 +    {
   12.84 +	retval=-1;
   12.85 +	if (g_error_matches(err,G_IO_ERROR,G_IO_ERROR_EXISTS))
   12.86 +	{
   12.87 +	    info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
   12.88 +	      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,NULL);
   12.89 +	    if (info)
   12.90 +	    {
   12.91 +		g_clear_error(&err);
   12.92 +		if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY)
   12.93 +		    retval=0;
   12.94 +		else
   12.95 +		    razor_set_error(error,RAZOR_POSIX_ERROR,EEXIST,uri,
   12.96 +		      "Not a directory");
   12.97 +		g_object_unref(info);
   12.98 +	    }
   12.99 +	}
  12.100 +	if (err)
  12.101 +	    plover_propagate_g_error(error,err);
  12.102 +    }
  12.103 +    else
  12.104 +	retval=0;
  12.105 +    g_object_unref(file);
  12.106 +    return retval;
  12.107 +}
  12.108 +
  12.109 +int uri_unlink(const char *uri,struct razor_error **error)
  12.110 +{
  12.111 +    GFile *file;
  12.112 +    gchar *path;
  12.113 +    int retval;
  12.114 +    GError *err=NULL;
  12.115 +    g_message("uri_unlink(%s)",uri);
  12.116 +    file=file_for_uri(uri);
  12.117 +    path=g_file_get_path(file);
  12.118 +    if (path)
  12.119 +    {
  12.120 +	retval=razor_file_default_unlink(path,error);
  12.121 +	g_free(path);
  12.122 +    }
  12.123 +    else if (!g_file_delete(file,NULL,&err))
  12.124 +    {
  12.125 +	plover_propagate_g_error(error,err);
  12.126 +	retval=-1;
  12.127 +    }
  12.128 +    else
  12.129 +	retval=0;
  12.130 +    g_object_unref(file);
  12.131 +    return retval;
  12.132 +}
  12.133 +
  12.134 +int uri_open(const char *uri,int flags,mode_t mode,struct razor_error **error)
  12.135 +{
  12.136 +    GFile *file;
  12.137 +    gchar *path;
  12.138 +    int retval;
  12.139 +    GError *err=NULL;
  12.140 +    g_message("uri_open(%s)",uri);
  12.141 +    file=file_for_uri(uri);
  12.142 +    path=g_file_get_path(file);
  12.143 +    if (path)
  12.144 +    {
  12.145 +	retval=razor_file_default_open(path,flags,mode,error);
  12.146 +	g_free(path);
  12.147 +    }
  12.148 +    else
  12.149 +    {
  12.150 +	razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED,
  12.151 +	  uri,"File is not local");
  12.152 +	retval=-1;
  12.153 +    }
  12.154 +    g_object_unref(file);
  12.155 +    return retval;
  12.156 +}
  12.157 +
  12.158 +int uri_move(const char *src_uri,const char *dst_uri,
  12.159 +  struct razor_error **error)
  12.160 +{
  12.161 +    GFile *src,*dst;
  12.162 +    gchar *src_path,*dst_path;
  12.163 +    int retval;
  12.164 +    GError *err=NULL;
  12.165 +    g_message("uri_move(%s,%s)",src_uri,dst_uri);
  12.166 +    src=file_for_uri(src_uri);
  12.167 +    dst=file_for_uri(dst_uri);
  12.168 +    src_path=g_file_get_path(src);
  12.169 +    dst_path=g_file_get_path(dst);
  12.170 +    if (src_path && dst_path)
  12.171 +	retval=razor_file_default_move(src_path,dst_path,error);
  12.172 +    else if (!g_file_move(src,dst,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&err))
  12.173 +    {
  12.174 +	plover_propagate_g_error(error,err);
  12.175 +	retval=-1;
  12.176 +    }
  12.177 +    else
  12.178 +	retval=0;
  12.179 +    g_free(src_path);
  12.180 +    g_free(dst_path);
  12.181 +    g_object_unref(src);
  12.182 +    g_object_unref(dst);
  12.183 +    return retval;
  12.184 +}
  12.185 +
  12.186 +static void *uri_get_contents(const char *uri,size_t *length,int private,
  12.187 +  struct razor_error **error)
  12.188 +{
  12.189 +    GFile *file;
  12.190 +    gchar *path;
  12.191 +    void *addr;
  12.192 +    char *contents;
  12.193 +    gsize len;
  12.194 +    GError *err=NULL;
  12.195 +    g_message("uri_get_contents(%s)",uri);
  12.196 +    file=file_for_uri(uri);
  12.197 +    path=g_file_get_path(file);
  12.198 +    if (path)
  12.199 +    {
  12.200 +	g_object_unref(file);
  12.201 +	addr=razor_file_default_get_contents(path,length,private,error);
  12.202 +	if (addr)
  12.203 +	    open_razor_files=g_list_prepend(open_razor_files,addr);
  12.204 +	g_free(path);
  12.205 +    }
  12.206 +    else if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err))
  12.207 +    {
  12.208 +	plover_propagate_g_error(error,err);
  12.209 +	g_object_unref(file);
  12.210 +	addr=NULL;
  12.211 +    }
  12.212 +    else
  12.213 +    {
  12.214 +	g_object_unref(file);
  12.215 +	addr=contents;
  12.216 +	if (length)
  12.217 +	    *length=len;
  12.218 +    }
  12.219 +    return addr;
  12.220 +}
  12.221 +
  12.222 +static int uri_free_contents(void *addr,size_t length)
  12.223 +{
  12.224 +    int retval;
  12.225 +    GList *lnk;
  12.226 +    g_message("uri_free_contents(%p)",addr);
  12.227 +    lnk=g_list_find(open_razor_files,addr);
  12.228 +    if (lnk)
  12.229 +    {
  12.230 +	open_razor_files=g_list_delete_link(open_razor_files,lnk);
  12.231 +	retval=razor_file_default_free_contents(addr,length);
  12.232 +    }
  12.233 +    else
  12.234 +    {
  12.235 +	g_free(addr);
  12.236 +	retval=0;
  12.237 +    }
  12.238 +    return retval;
  12.239 +}
  12.240 +
  12.241 +int uri_is_directory(const char *uri,struct razor_error **error)
  12.242 +{
  12.243 +    GFile *file;
  12.244 +    GFileInfo *info;
  12.245 +    gchar *path;
  12.246 +    int retval;
  12.247 +    GError *err=NULL;
  12.248 +    g_message("uri_is_directory(%s)",uri);
  12.249 +    file=file_for_uri(uri);
  12.250 +    path=g_file_get_path(file);
  12.251 +    if (path)
  12.252 +    {
  12.253 +	retval=razor_file_default_is_directory(path,error);
  12.254 +	g_free(path);
  12.255 +    }
  12.256 +    else
  12.257 +    {
  12.258 +	info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
  12.259 +	  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err);
  12.260 +	if (info)
  12.261 +	{
  12.262 +	    if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY)
  12.263 +		retval=1;
  12.264 +	    else
  12.265 +		retval=0;
  12.266 +	    g_object_unref(info);
  12.267 +	}
  12.268 +	else
  12.269 +	{
  12.270 +	    retval=-1;
  12.271 +	    plover_propagate_g_error(error,err);
  12.272 +	}
  12.273 +    }
  12.274 +    g_object_unref(file);
  12.275 +    return retval;
  12.276 +}
  12.277 +
  12.278 +char *uri_mkdtemp_near(const char *uri,const char *template,
  12.279 +  struct razor_error **error)
  12.280 +{
  12.281 +    GFile *file;
  12.282 +    gchar *path,*tmpuri;
  12.283 +    char *tmppath,*retval;
  12.284 +    GError *err=NULL;
  12.285 +    g_message("uri_mkdtemp_near(%s)",uri);
  12.286 +    file=file_for_uri(uri);
  12.287 +    path=g_file_get_path(file);
  12.288 +    g_object_unref(file);
  12.289 +    if (path)
  12.290 +    {
  12.291 +	tmppath=razor_file_default_mkdtemp_near(path,template,error);
  12.292 +	g_free(path);
  12.293 +	if (tmppath)
  12.294 +	{
  12.295 +	    file=g_file_new_for_path(tmppath);
  12.296 +	    tmpuri=g_file_get_uri(file);
  12.297 +	    g_object_unref(file);
  12.298 +	    retval=strdup(tmpuri);
  12.299 +	    g_free(tmpuri);
  12.300 +	}
  12.301 +	else
  12.302 +	    retval=NULL;
  12.303 +    }
  12.304 +    else
  12.305 +    {
  12.306 +	razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED,
  12.307 +	  uri,"File is not local");
  12.308 +	retval=NULL;
  12.309 +    }
  12.310 +    return retval;
  12.311 +}
  12.312 +
  12.313 +struct uri_dir {
  12.314 +    void *razor_file_default;
  12.315 +    GFileEnumerator *enumerator;
  12.316 +};
  12.317 +
  12.318 +void *uri_opendir(const char *uri,struct razor_error **error)
  12.319 +{
  12.320 +    GFile *file;
  12.321 +    gchar *path;
  12.322 +    struct uri_dir *dir;
  12.323 +    GError *err=NULL;
  12.324 +    g_message("uri_opendir(%s)",uri);
  12.325 +    dir=g_new0(struct uri_dir,1);
  12.326 +    file=file_for_uri(uri);
  12.327 +    path=g_file_get_path(file);
  12.328 +    if (path)
  12.329 +    {
  12.330 +	dir->razor_file_default=razor_file_default_opendir(path,error);
  12.331 +	if (!dir->razor_file_default)
  12.332 +	{
  12.333 +	    g_free(dir);
  12.334 +	    dir=NULL;
  12.335 +	}
  12.336 +	g_free(path);
  12.337 +    }
  12.338 +    else
  12.339 +    {
  12.340 +	dir->enumerator=g_file_enumerate_children(file,
  12.341 +	  G_FILE_ATTRIBUTE_STANDARD_NAME,G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
  12.342 +	  NULL,&err);
  12.343 +	if (!dir->enumerator)
  12.344 +	{
  12.345 +	    g_free(dir);
  12.346 +	    dir=NULL;
  12.347 +	    plover_propagate_g_error(error,err);
  12.348 +	}
  12.349 +    }
  12.350 +    g_object_unref(file);
  12.351 +    return dir;
  12.352 +}
  12.353 +
  12.354 +char *uri_readdir(void *dp,struct razor_error **error)
  12.355 +{
  12.356 +    struct uri_dir *dir=dp;
  12.357 +    char *name;
  12.358 +    GError *err=NULL;
  12.359 +    GFileInfo *info;
  12.360 +    g_message("uri_readdir(%p)",dp);
  12.361 +    if (dir->razor_file_default)
  12.362 +	name=razor_file_default_readdir(dir->razor_file_default,error);
  12.363 +    else
  12.364 +    {
  12.365 +	info=g_file_enumerator_next_file(dir->enumerator,NULL,&err);
  12.366 +	if (!info)
  12.367 +	{
  12.368 +	    name=NULL;
  12.369 +	    plover_propagate_g_error(error,err);
  12.370 +	}
  12.371 +	else
  12.372 +	{
  12.373 +	    name=strdup(g_file_info_get_name(info));
  12.374 +	    g_object_unref(info);
  12.375 +	}
  12.376 +    }
  12.377 +    return name;
  12.378 +}
  12.379 +
  12.380 +int uri_closedir(void *dp,struct razor_error **error)
  12.381 +{
  12.382 +    struct uri_dir *dir=dp;
  12.383 +    int retval;
  12.384 +    GError *err=NULL;
  12.385 +    g_message("uri_closedir(%p)",dp);
  12.386 +    if (dir->razor_file_default)
  12.387 +	retval=razor_file_default_closedir(dir->razor_file_default,error);
  12.388 +    else
  12.389 +    {
  12.390 +	retval=g_file_enumerator_close(dir->enumerator,NULL,&err)?0:-1;
  12.391 +	if (retval)
  12.392 +	    plover_propagate_g_error(error,err);
  12.393 +	g_object_unref(dir->enumerator);
  12.394 +    }
  12.395 +    g_free(dir);
  12.396 +    return retval;
  12.397 +}
  12.398 +
  12.399 +void plover__uri_handler_init(void)
  12.400 +{
  12.401 +    static gsize init=0;
  12.402 +    struct razor_uri_vtable uri_vtable={0,};
  12.403 +    g_message("plover__uri_handler_init()");
  12.404 +    if (g_once_init_enter(&init))
  12.405 +    {
  12.406 +	uri_vtable.structure_size=sizeof(uri_vtable);
  12.407 +	uri_vtable.mkdir=uri_mkdir;
  12.408 +	uri_vtable.unlink=uri_unlink;
  12.409 +	uri_vtable.open=uri_open;
  12.410 +	uri_vtable.move=uri_move;
  12.411 +	uri_vtable.get_contents=uri_get_contents;
  12.412 +	uri_vtable.free_contents=uri_free_contents;
  12.413 +	uri_vtable.is_directory=uri_is_directory;
  12.414 +	uri_vtable.mkdtemp_near=uri_mkdtemp_near;
  12.415 +	uri_vtable.opendir=uri_opendir;
  12.416 +	uri_vtable.readdir=uri_readdir;
  12.417 +	uri_vtable.closedir=uri_closedir;
  12.418 +	razor_uri_set_vtable(&uri_vtable);
  12.419 +	g_once_init_leave(&init,1);
  12.420 +    }
  12.421 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/plover/uri-handler.h	Wed Jun 22 17:04:28 2016 +0100
    13.3 @@ -0,0 +1,10 @@
    13.4 +#ifndef __URI_HANDLER_H__
    13.5 +#define __URI_HANDLER_H__
    13.6 +
    13.7 +G_BEGIN_DECLS
    13.8 +
    13.9 +void plover__uri_handler_init(void);
   13.10 +
   13.11 +G_END_DECLS
   13.12 +
   13.13 +#endif /* __URI_HANDLER_H__ */
    14.1 --- a/tests/Makefile.am	Thu Jun 16 18:00:21 2016 +0100
    14.2 +++ b/tests/Makefile.am	Wed Jun 22 17:04:28 2016 +0100
    14.3 @@ -54,10 +54,10 @@
    14.4  
    14.5  razor-test-dir/var/lib/razor/system.rzdb: primary.xml.gz
    14.6  	$(RM) -r razor-test-dir
    14.7 -	$(RAZOR) --root=razor-test-dir init
    14.8 -	$(RAZOR) --root=razor-test-dir \
    14.9 +	$(RAZOR) --root=file:razor-test-dir init
   14.10 +	$(RAZOR) --root=file:razor-test-dir \
   14.11  	  --url=file://localhost/`pwd`/yum-repo-test-dir import-yum
   14.12 -	$(RAZOR) --root=razor-test-dir install zap zappy zappy2 zappy-tools
   14.13 +	$(RAZOR) --root=file:razor-test-dir install zap zappy zappy2 zappy-tools
   14.14  
   14.15  endif
   14.16  
    15.1 --- a/tests/plover/Makefile.am	Thu Jun 16 18:00:21 2016 +0100
    15.2 +++ b/tests/plover/Makefile.am	Wed Jun 22 17:04:28 2016 +0100
    15.3 @@ -11,25 +11,25 @@
    15.4  
    15.5  test_programs = test-import-yum test-package test-repository test-packageset \
    15.6  	test-transaction test-comps test-log test-util test-razor test-vector \
    15.7 -	test-exception-handler test-fileio
    15.8 +	test-exception-handler test-uri-handler
    15.9  
   15.10  test_transaction_LDADD = $(LDADD) $(LUA_POSIX_LIBS)
   15.11  test_razor_LDADD = $(LDADD) $(LUA_POSIX_LIBS)
   15.12 -test_fileio_SOURCES = test-fileio.c test-fileio-gresource.c
   15.13 -test_fileio_DEPENDENCIES = test-fileio-gresource.h
   15.14 -test_fileio_LDADD = $(LDADD) $(LUA_POSIX_LIBS)
   15.15 +test_uri_handler_SOURCES = test-uri-handler.c test-uri-handler-gresource.c \
   15.16 +	test-uri-handler-gresource.h
   15.17 +test_uri_handler_LDADD = $(LDADD) $(LUA_POSIX_LIBS)
   15.18  
   15.19 -test-fileio-gresource.c: test-fileio.gresource.xml
   15.20 +test-uri-handler-gresource.c: test-uri-handler.gresource.xml
   15.21  	$(AM_V_GEN)$(COMPILE_RESOURCES) --target=$@ --generate \
   15.22  	  --sourcedir=../yum-repo-test-dir --manual-register \
   15.23 -	  test-fileio.gresource.xml
   15.24 +	  test-uri-handler.gresource.xml
   15.25  
   15.26 -test-fileio-gresource.h: test-fileio.gresource.xml
   15.27 +test-uri-handler-gresource.h: test-uri-handler.gresource.xml
   15.28  	$(AM_V_GEN)$(COMPILE_RESOURCES) --target=$@ --generate \
   15.29  	  --sourcedir=../yum-repo-test-dir --manual-register \
   15.30 -	  test-fileio.gresource.xml
   15.31 +	  test-uri-handler.gresource.xml
   15.32  
   15.33 -test-fileio.gresource.xml:
   15.34 +test-uri-handler.gresource.xml:
   15.35  	$(AM_V_GEN)(cd ../yum-repo-test-dir; \
   15.36  	  echo '<?xml version="1.0" encoding="UTF-8"?>'; \
   15.37  	  echo '<gresources>'; \
   15.38 @@ -46,5 +46,7 @@
   15.39  clean-local:
   15.40  	rm -rf test-log-rotate razor-test-dir-*
   15.41  
   15.42 -CLEANFILES = test-fileio-gresource.c test-fileio-gresource.h \
   15.43 -	test-fileio.gresource.xml
   15.44 +BUILT_SOURCES = test-uri-handler-gresource.c test-uri-handler-gresource.h
   15.45 +
   15.46 +CLEANFILES = test-uri-handler-gresource.c test-uri-handler-gresource.h \
   15.47 +	test-uri-handler.gresource.xml
    16.1 --- a/tests/plover/test-fileio.c	Thu Jun 16 18:00:21 2016 +0100
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,113 +0,0 @@
    16.4 -/*
    16.5 - * Copyright (C) 2009, 2011, 2016  J. Ali Harlow <ali@juiblex.co.uk>
    16.6 - *
    16.7 - * This program is free software; you can redistribute it and/or modify
    16.8 - * it under the terms of the GNU General Public License as published by
    16.9 - * the Free Software Foundation; either version 2 of the License, or
   16.10 - * (at your option) any later version.
   16.11 - *
   16.12 - * This program is distributed in the hope that it will be useful,
   16.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.15 - * GNU General Public License for more details.
   16.16 - *
   16.17 - * You should have received a copy of the GNU General Public License along
   16.18 - * with this program; if not, write to the Free Software Foundation, Inc.,
   16.19 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   16.20 - */
   16.21 -
   16.22 -#include <stdlib.h>
   16.23 -#include <stdio.h>
   16.24 -#include <string.h>
   16.25 -#include <limits.h>
   16.26 -#include <lua.h>
   16.27 -#include "config.h"
   16.28 -#include "plover/plover.h"
   16.29 -#include "test-fileio-gresource.h"
   16.30 -
   16.31 -LUALIB_API int luaopen_posix(lua_State *L);
   16.32 -
   16.33 -void test_resource(void)
   16.34 -{
   16.35 -    gchar *prefix,*root,*root_uri,*s;
   16.36 -    int ch,changed;
   16.37 -    struct comps *comps;
   16.38 -    struct comps_group *group;
   16.39 -    struct comps_requirement *pkg;
   16.40 -    struct plover_vector *packages=NULL;
   16.41 -    GError *error=NULL;
   16.42 -    GFile *file;
   16.43 -    test_fileio_register_resource();
   16.44 -    root=g_strdup("razor-test-dir-XXXXXX");
   16.45 -    g_assert(mkdtemp(root));
   16.46 -    file=g_file_new_for_path(root);
   16.47 -    root_uri=g_file_get_uri(file);
   16.48 -    g_object_unref(file);
   16.49 -    g_setenv("RAZOR_ROOT",root_uri,TRUE);
   16.50 -    g_free(root_uri);
   16.51 -    comps=plover_comps_new_from_uri(
   16.52 -      "resource:///uk/co/juiblex/project/plover/repodata/comps.xml");
   16.53 -    if (!comps)
   16.54 -    {
   16.55 -	perror("resource:///uk/co/juiblex/project/plover/repodata/comps.xml");
   16.56 -	exit(1);
   16.57 -    }
   16.58 -    prefix=plover_default_prefix_for_vendor(comps->vendor);
   16.59 -    group=plover_comps_lookup_group(comps,"base");
   16.60 -    if (!group)
   16.61 -    {
   16.62 -	fprintf(stderr,"No base group found in comps.xml\n");
   16.63 -	exit(1);
   16.64 -    }
   16.65 -    packages=plover_vector_new();
   16.66 -    do
   16.67 -    {
   16.68 -	changed=0;
   16.69 -	for(pkg=group->packages;pkg;pkg=pkg->next)
   16.70 -	{
   16.71 -	    if (plover_vector_contains(packages,pkg->name))
   16.72 -		continue;
   16.73 -	    if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
   16.74 -	      pkg->type==COMPS_REQUIREMENT_MANDATORY ||
   16.75 -	      pkg->type==COMPS_REQUIREMENT_CONDITIONAL && (!pkg->requires ||
   16.76 -	      plover_vector_contains(packages,pkg->requires)))
   16.77 -	    {
   16.78 -		changed++;
   16.79 -		plover_vector_append(packages,pkg->name);
   16.80 -	    }
   16.81 -	}
   16.82 -    } while(changed);
   16.83 -    plover_comps_free(comps);
   16.84 -    if (!packages->len)
   16.85 -    {
   16.86 -	fprintf(stderr,"No packages to install\n");
   16.87 -	exit(1);
   16.88 -    }
   16.89 -    if (!plover_install_uri("resource:///uk/co/juiblex/project/plover",prefix,
   16.90 -      packages->strings,&error))
   16.91 -    {
   16.92 -	fprintf(stderr,"%s\n",error->message);
   16.93 -	g_error_free(error);
   16.94 -	exit(1);
   16.95 -    }
   16.96 -    plover_vector_free(packages);
   16.97 -    g_free(prefix);
   16.98 -    g_unsetenv("RAZOR_ROOT");
   16.99 -    test_fileio_unregister_resource();
  16.100 -    s=g_build_filename(root,"usr/bin/zsh",NULL);
  16.101 -    g_free(root);
  16.102 -    if (!g_file_test(s,G_FILE_TEST_EXISTS))
  16.103 -	g_error("%s: Missing file",s);
  16.104 -    g_free(s);
  16.105 -}
  16.106 -
  16.107 -int main(int argc,char **argv)
  16.108 -{
  16.109 -    int retval;
  16.110 -    razor_set_lua_loader("posix",(void (*)())luaopen_posix);
  16.111 -    g_test_init(&argc,&argv,NULL);
  16.112 -    g_test_bug_base("mailto:ali@juiblex.co.uk");
  16.113 -    g_test_add_func("/fileio/resource",test_resource);
  16.114 -    retval=g_test_run();
  16.115 -    return retval;
  16.116 -}
    17.1 --- a/tests/plover/test-log.c	Thu Jun 16 18:00:21 2016 +0100
    17.2 +++ b/tests/plover/test-log.c	Wed Jun 22 17:04:28 2016 +0100
    17.3 @@ -165,7 +165,7 @@
    17.4      system("rm -rf test-log-rotate");
    17.5      g_assert(mkdir("test-log-rotate",0777)==0);
    17.6      cwd=g_get_current_dir();
    17.7 -    s=g_strconcat(cwd,"/",NULL);
    17.8 +    s=g_strconcat("file:",cwd,"/",NULL);
    17.9      g_free(cwd);
   17.10      g_setenv("RAZOR_ROOT",s,TRUE);
   17.11      g_free(s);
    18.1 --- a/tests/plover/test-package.c	Thu Jun 16 18:00:21 2016 +0100
    18.2 +++ b/tests/plover/test-package.c	Wed Jun 22 17:04:28 2016 +0100
    18.3 @@ -123,7 +123,7 @@
    18.4      struct razor_rpm *rpm;
    18.5      PloverPackage *package=NULL;
    18.6      struct razor_error *err=NULL;
    18.7 -    gchar *filename;
    18.8 +    gchar *uri;
    18.9      if (test_set)
   18.10      {
   18.11  	razor_set_unref(test_set);
   18.12 @@ -135,12 +135,12 @@
   18.13       * razor_importer_add_rpm() doesn't support prefixes so we have
   18.14       * to do it the really hard way.
   18.15       */
   18.16 -    filename=g_strconcat("../yum-repo-test-dir/rpms/",name,"-",version,
   18.17 +    uri=g_strconcat("file:../yum-repo-test-dir/rpms/",name,"-",version,
   18.18        ".noarch.rpm",NULL);
   18.19 -    rpm=razor_rpm_open(filename,&err);
   18.20 +    rpm=razor_rpm_open(uri,&err);
   18.21      if (!rpm)
   18.22 -	g_error("%s: %s",filename,razor_error_get_msg(err));
   18.23 -    g_free(filename);
   18.24 +	g_error("%s: %s",uri,razor_error_get_msg(err));
   18.25 +    g_free(uri);
   18.26      if (import_rpm(rpm))
   18.27  	package=plover_package_new(test_set,test_pkg);
   18.28      else
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tests/plover/test-uri-handler.c	Wed Jun 22 17:04:28 2016 +0100
    19.3 @@ -0,0 +1,114 @@
    19.4 +/*
    19.5 + * Copyright (C) 2009, 2011, 2016  J. Ali Harlow <ali@juiblex.co.uk>
    19.6 + *
    19.7 + * This program is free software; you can redistribute it and/or modify
    19.8 + * it under the terms of the GNU General Public License as published by
    19.9 + * the Free Software Foundation; either version 2 of the License, or
   19.10 + * (at your option) any later version.
   19.11 + *
   19.12 + * This program is distributed in the hope that it will be useful,
   19.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.15 + * GNU General Public License for more details.
   19.16 + *
   19.17 + * You should have received a copy of the GNU General Public License along
   19.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
   19.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   19.20 + */
   19.21 +
   19.22 +#include <stdlib.h>
   19.23 +#include <stdio.h>
   19.24 +#include <string.h>
   19.25 +#include <limits.h>
   19.26 +#include <lua.h>
   19.27 +#include "config.h"
   19.28 +#include "plover/plover.h"
   19.29 +#include "plover/uri-handler.h"
   19.30 +#include "test-uri-handler-gresource.h"
   19.31 +
   19.32 +LUALIB_API int luaopen_posix(lua_State *L);
   19.33 +
   19.34 +void test_resource(void)
   19.35 +{
   19.36 +    gchar *prefix,*root,*root_uri,*s;
   19.37 +    int ch,changed;
   19.38 +    struct comps *comps;
   19.39 +    struct comps_group *group;
   19.40 +    struct comps_requirement *pkg;
   19.41 +    struct plover_vector *packages=NULL;
   19.42 +    GError *error=NULL;
   19.43 +    GFile *file;
   19.44 +    test_uri_handler_register_resource();
   19.45 +    root=g_strdup("razor-test-dir-XXXXXX");
   19.46 +    g_assert(mkdtemp(root));
   19.47 +    file=g_file_new_for_path(root);
   19.48 +    root_uri=g_file_get_uri(file);
   19.49 +    g_object_unref(file);
   19.50 +    g_setenv("RAZOR_ROOT",root_uri,TRUE);
   19.51 +    g_free(root_uri);
   19.52 +    comps=plover_comps_new_from_uri(
   19.53 +      "resource:///uk/co/juiblex/project/plover/repodata/comps.xml");
   19.54 +    if (!comps)
   19.55 +    {
   19.56 +	perror("resource:///uk/co/juiblex/project/plover/repodata/comps.xml");
   19.57 +	exit(1);
   19.58 +    }
   19.59 +    prefix=plover_default_prefix_for_vendor(comps->vendor);
   19.60 +    group=plover_comps_lookup_group(comps,"base");
   19.61 +    if (!group)
   19.62 +    {
   19.63 +	fprintf(stderr,"No base group found in comps.xml\n");
   19.64 +	exit(1);
   19.65 +    }
   19.66 +    packages=plover_vector_new();
   19.67 +    do
   19.68 +    {
   19.69 +	changed=0;
   19.70 +	for(pkg=group->packages;pkg;pkg=pkg->next)
   19.71 +	{
   19.72 +	    if (plover_vector_contains(packages,pkg->name))
   19.73 +		continue;
   19.74 +	    if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
   19.75 +	      pkg->type==COMPS_REQUIREMENT_MANDATORY ||
   19.76 +	      pkg->type==COMPS_REQUIREMENT_CONDITIONAL && (!pkg->requires ||
   19.77 +	      plover_vector_contains(packages,pkg->requires)))
   19.78 +	    {
   19.79 +		changed++;
   19.80 +		plover_vector_append(packages,pkg->name);
   19.81 +	    }
   19.82 +	}
   19.83 +    } while(changed);
   19.84 +    plover_comps_free(comps);
   19.85 +    if (!packages->len)
   19.86 +    {
   19.87 +	fprintf(stderr,"No packages to install\n");
   19.88 +	exit(1);
   19.89 +    }
   19.90 +    if (!plover_install_uri("resource:///uk/co/juiblex/project/plover",prefix,
   19.91 +      packages->strings,&error))
   19.92 +    {
   19.93 +	fprintf(stderr,"%s\n",error->message);
   19.94 +	g_error_free(error);
   19.95 +	exit(1);
   19.96 +    }
   19.97 +    plover_vector_free(packages);
   19.98 +    g_free(prefix);
   19.99 +    g_unsetenv("RAZOR_ROOT");
  19.100 +    test_uri_handler_unregister_resource();
  19.101 +    s=g_build_filename(root,"usr/bin/zsh",NULL);
  19.102 +    g_free(root);
  19.103 +    if (!g_file_test(s,G_FILE_TEST_EXISTS))
  19.104 +	g_error("%s: Missing file",s);
  19.105 +    g_free(s);
  19.106 +}
  19.107 +
  19.108 +int main(int argc,char **argv)
  19.109 +{
  19.110 +    int retval;
  19.111 +    razor_set_lua_loader("posix",(void (*)())luaopen_posix);
  19.112 +    g_test_init(&argc,&argv,NULL);
  19.113 +    g_test_bug_base("mailto:ali@juiblex.co.uk");
  19.114 +    g_test_add_func("/uri-handler/resource",test_resource);
  19.115 +    retval=g_test_run();
  19.116 +    return retval;
  19.117 +}