# HG changeset patch # User J. Ali Harlow # Date 1250186476 -3600 # Node ID 868db5c1f2d7665ff05db2522db8313e785fc1e1 # Parent 1f06562182cbd27431d2f6bf74e8255effd6959a Add an update command diff -r 1f06562182cb -r 868db5c1f2d7 .gitignore --- a/.gitignore Thu Aug 13 12:42:26 2009 +0100 +++ b/.gitignore Thu Aug 13 19:01:16 2009 +0100 @@ -16,3 +16,5 @@ plover/plover.pc setup/resources.rc setup/setup +update/resources.rc +update/update diff -r 1f06562182cb -r 868db5c1f2d7 Makefile.am --- a/Makefile.am Thu Aug 13 12:42:26 2009 +0100 +++ b/Makefile.am Thu Aug 13 19:01:16 2009 +0100 @@ -1,1 +1,1 @@ -SUBDIRS=plover setup +SUBDIRS=plover setup update diff -r 1f06562182cb -r 868db5c1f2d7 configure.ac --- a/configure.ac Thu Aug 13 12:42:26 2009 +0100 +++ b/configure.ac Thu Aug 13 19:01:16 2009 +0100 @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([plover],[0.1],[ali@juiblex.co.uk]) +AC_INIT([plover],[0.2],[ali@juiblex.co.uk]) AC_PREREQ(2.59) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_SRCDIR([plover/plover.h]) @@ -11,6 +11,8 @@ plover/plover.pc setup/Makefile setup/resources.rc +update/Makefile +update/resources.rc ]) AM_INIT_AUTOMAKE(no-define) case $VERSION in diff -r 1f06562182cb -r 868db5c1f2d7 plover/plover.h --- a/plover/plover.h Thu Aug 13 12:42:26 2009 +0100 +++ b/plover/plover.h Thu Aug 13 19:01:16 2009 +0100 @@ -34,6 +34,8 @@ }; char *plover_strconcat(const char *string,...); +char *plover_default_prefix_for_vendor(const char *vendor); +char *plover_get_program_directory(const char *argv0); struct razor_set *plover_razor_set_create_from_yum(const char *base); diff -r 1f06562182cb -r 868db5c1f2d7 plover/razor.c --- a/plover/razor.c Thu Aug 13 12:42:26 2009 +0100 +++ b/plover/razor.c Thu Aug 13 19:01:16 2009 +0100 @@ -262,6 +262,91 @@ return razor_root_commit(root); } +int plover_update(const char *base,const char *prefix,char **pkgs) +{ + int i; + char *install_root,*s; + struct razor_root *root; + struct razor_set *system,*set,*upstream,*next; + struct razor_transaction *trans; + struct razor_relocations *relocations; + install_root=getenv("RAZOR_ROOT"); + if (!install_root) + install_root=""; + if (prefix) + { + relocations=razor_relocations_create(); + razor_relocations_add(relocations,"/usr",prefix); + } + set=razor_root_open_read_only(install_root); + if (!set) + return 0; + razor_set_destroy(set); + root=razor_root_open(install_root); + if (!root) + return -1; + system=razor_root_get_system_set(root); + if (!system) + { + razor_root_close(root); + return -1; + } + s=plover_strconcat(base,"/repodata",NULL); + if (!s) + { + razor_root_close(root); + return -1; + } + if (chdir(s)<0) + { + perror(s); + free(s); + razor_root_close(root); + return -1; + } + free(s); + set=plover_razor_set_create_from_yum(base); + if (!set) + { + razor_root_close(root); + return -1; + } + upstream=plover_relocate_packages(set,base,relocations); + razor_set_destroy(set); + trans=razor_transaction_create(system,upstream); + if (pkgs) + for(i=0;pkgs[i];i++) + { + if (plover_mark_package_for_update(trans,system,pkgs[i])) + { + fprintf(stderr,"%s: Package not found\n",pkgs[i]); + razor_transaction_destroy(trans); + razor_set_destroy(upstream); + razor_set_destroy(system); + razor_root_close(root); + return -1; + } + } + else + razor_transaction_update_all(trans); + razor_transaction_resolve(trans); + if (razor_transaction_describe(trans)>0) + { + razor_transaction_destroy(trans); + razor_set_destroy(upstream); + razor_set_destroy(system); + razor_root_close(root); + return -1; + } + next=razor_transaction_commit(trans); + plover_run_transaction(trans,base,install_root,system,next,relocations); + razor_root_update(root,next); + razor_transaction_destroy(trans); + razor_set_destroy(next); + razor_set_destroy(upstream); + return razor_root_commit(root); +} + static int plover_mark_packages_for_removal(struct razor_transaction *trans, struct razor_set *set,const char *pkg) { diff -r 1f06562182cb -r 868db5c1f2d7 plover/util.c --- a/plover/util.c Thu Aug 13 12:42:26 2009 +0100 +++ b/plover/util.c Thu Aug 13 19:01:16 2009 +0100 @@ -19,6 +19,11 @@ #include #include #include +#include +#ifdef WIN32 +#include +#include +#endif #include "config.h" #include "plover.h" @@ -51,3 +56,46 @@ } return result; } + +char *plover_default_prefix_for_vendor(const char *vendor) +{ +#ifdef WIN32 + char path[PATH_MAX]; + SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0, + path); + return plover_strconcat(path,"\\",vendor?vendor:"Plover",NULL); +#else + return NULL; +#endif +} + +/* + * Get the directory containing the program executable. + */ + +char *plover_get_program_directory(const char *argv0) +{ + char *s; +#ifdef WIN32 + char path[PATH_MAX],*t; + GetModuleFileName(NULL,path,sizeof(path)); + s=strrchr(path,'/'); + if (s) + { + t=strrchr(s,'\\'); + if (t) + s=t; + } + else + s=strrchr(path,'\\'); + if (s) + *s='\0'; + return strdup(path); +#else + s=argv0?strrchr(argv0,'/'):NULL; + if (s) + return strndup(argv0,s-argv0); + else + return strdup("."); +#endif +} diff -r 1f06562182cb -r 868db5c1f2d7 setup/setup.c --- a/setup/setup.c Thu Aug 13 12:42:26 2009 +0100 +++ b/setup/setup.c Thu Aug 13 19:01:16 2009 +0100 @@ -86,34 +86,15 @@ return realloc(ptr,nsize); } -void setup() +void setup(const char *argv0) { - char path[PATH_MAX],*s,*t,*prefix; + char *path,*s,*prefix; int changed; struct comps *comps; struct comps_group *group; struct comps_requirement *pkg; struct vector *packages=NULL; -#ifdef WIN32 - SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0, - path); - prefix=strdup(path); - GetModuleFileName(NULL,path,sizeof(path)); - s=strrchr(path,'/'); - if (s) - { - t=strrchr(s,'\\'); - if (t) - s=t; - } - else - s=strrchr(path,'\\'); - if (s) - *s='\0'; -#else - strcpy(path,"/tmp"); - prefix=NULL; -#endif + path=plover_get_program_directory(argv0); s=plover_strconcat(path,"/repodata/comps.xml",NULL); comps=plover_comps_new_from_file(s); if (!comps) @@ -122,11 +103,7 @@ exit(1); } free(s); -#ifdef WIN32 - s=plover_strconcat(prefix,"\\",comps->vendor?comps->vendor:"Plover",NULL); - free(prefix); - prefix=s; -#endif + prefix=plover_default_prefix_for_vendor(comps->vendor); group=plover_comps_lookup_group(comps,"base"); if (!group) { @@ -151,6 +128,7 @@ } } } while(changed); + plover_comps_free(comps); if (!packages->len) { fprintf(stderr,"No packages to install\n"); @@ -158,10 +136,8 @@ } plover_install(path,prefix,packages->strings); vector_free(packages); - plover_comps_free(comps); -#ifdef WIN32 free(prefix); -#endif + free(path); } int main(int argc,char **argv) @@ -171,5 +147,5 @@ if (argc>1 && !strcmp(argv[1],"-u")) plover_remove(NULL); else - setup(); + setup(argv[0]); } diff -r 1f06562182cb -r 868db5c1f2d7 update/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/update/Makefile.am Thu Aug 13 19:01:16 2009 +0100 @@ -0,0 +1,22 @@ +AM_CFLAGS=-g $(SETUP_CFLAGS) +LDADD=../plover/libplover.la $(SETUP_LIBS) +INCLUDES=-I$(top_srcdir) + +bin_PROGRAMS=update + +update_SOURCES=update.c +update_LDFLAGS=-all-static +if HAVE_WINDRES +update_SOURCES+=resources.rc +endif + +.png.pnm: + pngtopnm $< | pnmquant 256 > $@ + +resources.$(OBJEXT): resources.rc update.ico + $(WINDRES) resources.rc $@ + +update.ico: icon16.pnm icon22.pnm icon32.pnm + ppmtowinicon -output=$@ $^ + +EXTRA_DIST=icon16.png icon22.png icon32.png diff -r 1f06562182cb -r 868db5c1f2d7 update/icon16.png Binary file update/icon16.png has changed diff -r 1f06562182cb -r 868db5c1f2d7 update/icon22.png Binary file update/icon22.png has changed diff -r 1f06562182cb -r 868db5c1f2d7 update/icon32.png Binary file update/icon32.png has changed diff -r 1f06562182cb -r 868db5c1f2d7 update/resources.rc.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/update/resources.rc.in Thu Aug 13 19:01:16 2009 +0100 @@ -0,0 +1,32 @@ +#include + +MAINICON ICON "update.ico" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@,@PLOVER_MICRO_VERS +ION@,0 + PRODUCTVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@,@PLOVER_MICRO_V +ERSION@,0 + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + { + BLOCK "StringFileInfo" + { + BLOCK "080904B0" + { + VALUE "CompanyName","The plover development team" + VALUE "FileDescription","Plover setup program" + VALUE "FileVersion","@PACKAGE_VERSION@" + VALUE "InternalName","update" + VALUE "LegalCopyright", + "Copyright (c) 2009 J. Ali Harlow et al" + VALUE "OriginalFilename","update.exe" + VALUE "ProductName","plover" + VALUE "ProductVersion","@PACKAGE_VERSION@" + } + } + BLOCK "VarFileInfo" + { + VALUE "Translation",0x809,0x4B0 + } + } diff -r 1f06562182cb -r 868db5c1f2d7 update/update.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/update/update.c Thu Aug 13 19:01:16 2009 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009 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 "config.h" +#include "plover/plover.h" +#include "whelk/whelk.h" + +LUALIB_API int luaopen_posix(lua_State *L); + +void update(const char *argv0) +{ + char *path,*s,*prefix; + struct comps *comps; + path=plover_get_program_directory(argv0); + s=plover_strconcat(path,"/repodata/comps.xml",NULL); + comps=plover_comps_new_from_file(s); + if (!comps) + { + perror(s); + exit(1); + } + free(s); + prefix=plover_default_prefix_for_vendor(comps->vendor); + plover_comps_free(comps); + plover_update(path,prefix,NULL); + free(prefix); + free(path); +} + +int main(int argc,char **argv) +{ + razor_set_lua_loader("posix",luaopen_posix); + razor_set_lua_loader("whelk",luaopen_whelk); + update(argv[0]); +}