summaryrefslogtreecommitdiffstats
path: root/RPM4/lib/RPM4/Transaction.pm
diff options
context:
space:
mode:
authornanardon <nanardon@971eb68f-4bfb-0310-8326-d2484c010a4c>2005-10-04 04:08:46 +0000
committernanardon <nanardon@971eb68f-4bfb-0310-8326-d2484c010a4c>2005-10-04 04:08:46 +0000
commit9e2966a33f9148fdc8ef81783bab1fe18e87bd34 (patch)
tree7497629483bdfca79e64991306f251dfdc9bdafb /RPM4/lib/RPM4/Transaction.pm
parent588601a22c421404c9db24e0a47330d2186977f9 (diff)
downloadperl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar
perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar.gz
perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar.bz2
perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar.xz
perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.zip
- move to trunk
git-svn-id: svn+ssh://haiku.zarb.org/home/projects/rpm4/svn/trunk@36 971eb68f-4bfb-0310-8326-d2484c010a4c
Diffstat (limited to 'RPM4/lib/RPM4/Transaction.pm')
-rw-r--r--RPM4/lib/RPM4/Transaction.pm195
1 files changed, 195 insertions, 0 deletions
diff --git a/RPM4/lib/RPM4/Transaction.pm b/RPM4/lib/RPM4/Transaction.pm
new file mode 100644
index 0000000..a62be4d
--- /dev/null
+++ b/RPM4/lib/RPM4/Transaction.pm
@@ -0,0 +1,195 @@
+##- Nanar <nanardon@mandrake.org>
+##-
+##- 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+use strict;
+use warnings;
+use RPM4::Transaction::Problems;
+
+package RPM4::Transaction;
+
+sub newspec {
+ my ($self, $filename, %options) = @_;
+ $options{transaction} = $self;
+ RPM4::Spec->new(
+ $filename,
+ %options
+ );
+}
+
+sub transpbs {
+ my ($self) = @_;
+ return RPM4::Transaction::Problems->new($self);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Hdlist::Db
+
+=head1 DESCRIPTION
+
+This object allow to access to the rpm datadase and installing rpms on the
+system.
+
+=head1 METHODS
+
+=head2 Hdlist::Db->traverse_headers(sub)
+
+Go through the rpm database and for each header run the callback passed as
+argument.
+
+Argument passed to the callback function is the current header as a Hdlist::Header object.
+
+Ex:
+ $db->traverse_headers( sub {
+ my ($h) = @_;
+ print $h->queryformat("%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}");
+ });
+
+
+=head2 Hdlist::Db->injectheader($header)
+
+Add the header into rpmdb. This is not installing a package, the function
+only fill information into the rpmdb.
+
+Return 0 on success.
+
+=head2 Hdlist::Db->deleteheader($index)
+
+Remove header from rpmdb locate at $index. This is not uninstalling a package,
+this function only delete information from rpmdb.
+
+Return 0 on success
+
+=head2 Hdlist::Db->transadd(header, filename, upgrade, relocation, force)
+
+Add rpm headers for next transaction. This means this rpm are going to be
+installed on the system.
+
+- header is an Hdlist::Header object,
+
+- filename, if given, is the rpm file you want to install, and should
+of course match the header,
+
+- upgrade is a boolean flag to indicate whether the rpm is going to be upgraded
+(1 by default).
+
+Returns 0 on success.
+
+See: $Hdlist::Db->transcheck(), $Hdlist::Db->transrun().
+
+=head2 Hdlist::Db->transremove(rpm_name)
+
+Add rpm to remove for next transaction. This mean the rpm will be uninstalled
+from the system.
+
+Argument is the exact rpm name (%{NAME}) or a string as NAME(EPOCH:VERSION-RELEASE).
+
+Returns the number of selected rpms for this transaction.
+
+=head2 Hdlist::Db->transcheck()
+
+Check current transaction is possible.
+
+Returns 0 on success, 1 on error during check.
+
+=head2 Hdlist::Db->transorder()
+
+Call to rpmlib to order the transaction, aka sort rpm installation /
+desintallation.
+
+Returns 0 on success.
+
+=head2 Hdlist::Db->transpb
+
+Return an array of problem found during L<Hdlist::Db->transcheck> or
+L<Hdlist::Db->transrun>
+
+=head2 Hdlist::Db->transrun($callback, $flags...)
+
+Really run transaction and install/uninstall packages.
+
+$callback can be:
+
+- undef value, let rpm show progression with some default value.
+
+- array ref: each value represent a rpm command line options:
+
+ PERCENT: show percentage of progress (--percent)
+ HASH: print '#' during progression (--hash)
+ LABEL: show rpm name (--verbose)
+
+- code ref: rpm is fully silent, the perl sub is called instead. Arguments
+passed to the subroutine are in a hash:
+
+ filename => opened filename
+ header => current header in transaction
+ what => current transaction process
+ amount => amount of transaction
+ total => number of transaction to do
+
+flags: list of flags to set for transaction (see rpm man page):
+
+I<From rpm Transaction flag>:
+
+ - NOSCRIPTS: --noscripts
+ - JUSTDB: --justdb
+ - NOTRIGGERS: --notriggers
+ - NODOCS: --excludedocs
+ - ALLFILES: --allfiles
+ - DIRSTASH: --dirstash
+ - REPACKAGE: --repackage
+ - NOTRIGGERPREIN: --notriggerprein
+ - NOPRE: --nopre
+ - NOPOST: --nopost
+ - NOTRIGGERIN: --notriggerin
+ - NOTRIGGERUN: --notriggerun
+ - NOPREUN: --nopreun
+ - NOPOSTUN: --nopostun
+ - NOTRIGGERPOSTUN: --notriggerpostun
+ - NOSUGGEST: --nosuggest
+ - NOMD5: --nomd5
+ - ADDINDEPS: --aid
+ - noscripts: Do not running any scripts, neither triggers
+
+I<From rpm prob filter>
+
+ - IGNOREOS: --ignoreos
+ - IGNOREARCH: --ignorearch
+ - REPLACEPKG: --replacepkgs
+ - REPLACENEWFILES: --replacefiles
+ - REPLACEOLDFILES: --replacefiles
+ - OLDPACKAGES: --oldpackage
+ - DISKSPACE: --ignoresize
+ - DISKNODE: --ignoresize
+
+Returns 0 on success.
+
+=head2 $db->transpbs
+
+Return a Hdlist::Db::Problems object containing problem found during
+rpms installation/desinstallation.
+
+See L<Hdlist::Db::Problems>
+
+=head1 SEE ALSO
+
+L<Hdlist>
class="hl opt">) i++; if (i == j) { i++; continue; } name = memdup(&buf[j], i-j + 1); name[i-j] = '\0'; if (buf[i] == '=') { int k = i+1; i++; while (buf[i] != ' ' && buf[i] != '\0') i++; value = memdup(&buf[k], i-k + 1); value[i-k] = '\0'; } params[param_number].name = name; params[param_number].value = value; param_number++; if (!strcmp(name, "changedisk")) set_param(MODE_CHANGEDISK); if (!strcmp(name, "updatemodules") || !strcmp(name, "thirdparty")) set_param(MODE_THIRDPARTY); if (!strcmp(name, "rescue") || !strcmp(name, "kamethod")) set_param(MODE_RESCUE); if (!strcmp(name, "rescue")) set_param(MODE_RESCUE); if (!strcmp(name, "keepmounted")) set_param(MODE_KEEP_MOUNTED); if (!strcmp(name, "noauto")) set_param(MODE_NOAUTO); if (!strcmp(name, "netauto")) set_param(MODE_NETAUTO); if (!strcmp(name, "debugstage1")) set_param(MODE_DEBUGSTAGE1); if (!strcmp(name, "automatic")) { set_param(MODE_AUTOMATIC); grab_automatic_params(value); } if (buf[i] == '\0') break; i++; } if (IS_AUTOMATIC && strcmp(get_auto_value("thirdparty"), "")) { set_param(MODE_THIRDPARTY); } log_message("\tgot %d args", param_number); } int stage1_mode = 0; int get_param(int i) { #ifdef SPAWN_INTERACTIVE static int fd = 0; char buf[5000]; char * ptr; int nb; if (fd <= 0) { fd = open(interactive_fifo, O_RDONLY); if (fd == -1) return (stage1_mode & i); fcntl(fd, F_SETFL, O_NONBLOCK); } if (fd > 0) { if ((nb = read(fd, buf, sizeof(buf))) > 0) { buf[nb] = '\0'; ptr = buf; while ((ptr = strstr(ptr, "+ "))) { if (!strncmp(ptr+2, "rescue", 6)) set_param(MODE_RESCUE); ptr++; } ptr = buf; while ((ptr = strstr(ptr, "- "))) { if (!strncmp(ptr+2, "rescue", 6)) unset_param(MODE_RESCUE); ptr++; } } } #endif return (stage1_mode & i); } char * get_param_valued(char *param_name) { int i; for (i = 0; i < param_number ; i++) if (!strcmp(params[i].name, param_name)) return params[i].value; return NULL; } void set_param_valued(char *param_name, char *param_value) { params[param_number].name = param_name; params[param_number].value = param_value; param_number++; } void set_param(int i) { stage1_mode |= i; } void unset_param(int i) { stage1_mode &= ~i; } void unset_automatic(void) { log_message("unsetting automatic"); unset_param(MODE_AUTOMATIC); exit_bootsplash(); }