aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acm/acm_db.php
diff options
context:
space:
mode:
authorBart van Bragt <bartvb@users.sourceforge.net>2005-03-17 22:41:20 +0000
committerBart van Bragt <bartvb@users.sourceforge.net>2005-03-17 22:41:20 +0000
commita6d2d210db5b5a17079d343bb494cc4ff6ca7583 (patch)
treef22de1e7aa9088ce63a54e496db79ad80bf2096d /phpBB/includes/acm/acm_db.php
parent4269b318a29f3cff9da6bdf2f7cff959dcb0c961 (diff)
downloadforums-a6d2d210db5b5a17079d343bb494cc4ff6ca7583.tar
forums-a6d2d210db5b5a17079d343bb494cc4ff6ca7583.tar.gz
forums-a6d2d210db5b5a17079d343bb494cc4ff6ca7583.tar.bz2
forums-a6d2d210db5b5a17079d343bb494cc4ff6ca7583.tar.xz
forums-a6d2d210db5b5a17079d343bb494cc4ff6ca7583.zip
Show a useful error message if a language file is missing
git-svn-id: file:///svn/phpbb/trunk@5104 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acm/acm_db.php')
0 files changed, 0 insertions, 0 deletions
23 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
package urpm;


no warnings 'utf8';
use strict;
use File::Find ();
use urpm::msg;
use urpm::download;
use urpm::util qw(basename begins_with cat_ cat_utf8 dirname file2absolute_file member);
use urpm::sys;
use urpm::cfg;
use urpm::md5sum;
# perl_checker: require urpm::args
# perl_checker: require urpm::media
# perl_checker: require urpm::parallel

our $VERSION = 'v8.115';
our @ISA = qw(URPM Exporter);
our @EXPORT_OK = ('file_from_local_url', 'file_from_local_medium', 'is_local_medium');

# Prepare exit code.  If you change this, the exiting with a failure and the message given will be postponed to the end of the overall processing.
our $postponed_msg = N("While some packages may have been installed, there were failures.\n");
our $postponed_code = 0;

use URPM;
use URPM::Resolve;


=head1 NAME

urpm - Mageia perl tools to handle the urpmi database

=head1 DESCRIPTION

C<urpm> is used by urpmi executables to manipulate packages and media
on a Mageia Linux distribution.

=head2 The urpm class

=over 4

=cut

#- this violently overrides is_arch_compat() to always return true.
sub shunt_ignorearch {
    eval q( sub URPM::Package::is_arch_compat { 1 } );
}

sub xml_info_policies() { qw(never on-demand update-only always) }

sub default_options {
    { 
	'split-level' => 1,
	'split-length' => 50,
	'verify-rpm' => 1,
	'post-clean' => 1,
	'xml-info' => 'on-demand',
	'max-round-robin-tries' => 5,
	'max-round-robin-probes' => 2,
	'days-between-mirrorlist-update' => 5,
	'nb-of-new-unrequested-pkgs-between-auto-select-orphans-check' => 10,
    };
}

=item urpm->new()

The constructor creates a new urpm object. It's a blessed hash that
contains fields from L<URPM>, and also the following fields:

B<source>: { id => src_rpm_file|spec_file }

B<media>: [ { 
   start => int, end => int, name => string, url => string,
   virtual => bool, media_info_dir => string, with_synthesis => string,
   no-media-info => bool,
   iso => string, downloader => string,
   ignore => bool, update => bool, modified => bool, really_modified => bool,
   unknown_media_info => bool, 
 } ],

B<options>: hashref of urpm options

several paths:

=over

B<config>: path of  urpmi.cfg (/etc/urpmi/urpmi.cfg)

B<mediacfgdir>: path of mediacfg.d (/etc/urpmi/mediacfg.d)

B<skiplist>: path of skip.list (/etc/urpmi/skip.list),

B<instlist>: path of inst.list (/etc/urpmi/inst.list),

B<prefer_list>: path of prefer.list (/etc/urpmi/prefer.list),

B<prefer_vendor_list>: path of prefer.vendor.list (/etc/urpmi/prefer.vendor.list),

B<private_netrc>: path of netrc (/etc/urpmi/netrc),

B<statedir>: state directory (/var/lib/urpmi),

B<cachedir>: cache directory (/var/cache/urpmi),

B<root>: path of the rooted system (when using global urpmi config),

B<urpmi_root>: path of the rooted system (when both urpmi & rpmdb are chrooted)

=back

Several subs:

=over

B<fatal>: sub for relaying fatal errors (should popup in GUIes)

B<error>: sub for relaying other errors

B<log>: sub for relaying messages if --verbose

B<print>: sub for always displayed messages, enable to redirect output for eg: installer

B<info>: sub for messages displayed unless --quiet

=back

All C<URPM> methods are available on an urpm object.

=cut

sub new {
    my ($class) = @_;
    my $self;
    $self = bless {
	# from URPM
	depslist   => [],
	provides   => {},
	obsoletes  => {},

	media      => undef,
	options    => {},

	fatal      => sub { printf STDERR "%s\n", $_[1]; exit($_[0]) },
	error      => sub { printf STDERR "%s\n", $_[0] },
	info       => sub { printf "%s\n", $_[0] }, #- displayed unless --quiet
	log        => sub { printf "%s\n", $_[0] }, #- displayed if --verbose
	print      => sub { printf "%s\n", $_[0] }, #- always displayed, enable to redirect output for eg: installer
    }, $class;

    set_files($self, '');
    $self->set_nofatal(1);
    $self;
}

=item urpm->new_parse_cmdline()

Like urpm->new but also parse the command line and parse the configuration file.

=cut

sub new_parse_cmdline {
    my ($class) = @_;
    my $urpm = $class->new;
    urpm::args::parse_cmdline(urpm => $urpm);
    get_global_options($urpm);
    $urpm;
}

sub _add2hash { my ($a, $b) = @_; while (my ($k, $v) = each %{$b || {}}) { defined $a->{$k} or $a->{$k} = $v } $a }

sub get_global_options {
    my ($urpm) = @_;

    my $config = urpm::cfg::load_config($urpm->{config})
      or $urpm->{fatal}(6, $urpm::cfg::err);

    if (my $global = $config->{global}) {
	_add2hash($urpm->{options}, $global);
    }
    #- remember global options for write_config
    $urpm->{global_config} = $config->{global};

    _add2hash($urpm->{options}, default_options());
}

sub prefer_rooted {
    my ($root, $file) = @_;
    -e "$root$file" ? "$root$file" : $file;
}

sub check_dir {
    my ($urpm, $dir) = @_;
    -d $dir && ! -l $dir or $urpm->{fatal}(1, N("fail to create directory %s", $dir));
    -o $dir && -w $dir or $urpm->{fatal}(1, N("invalid owner for directory %s", $dir));
}

sub init_dir {
    my ($urpm, $dir) = @_;

    mkdir $dir, 0755; # try to create it

    check_dir($urpm, $dir);

    mkdir "$dir/partial";
    mkdir "$dir/rpms";

    $dir;
}

sub userdir_prefix {
    my ($_urpm) = @_;
    '/tmp/.urpmi-';
}

sub valid_statedir {
    my ($urpm) = @_;
    $< or return;

    my $dir = ($urpm->{urpmi_root} || '') . userdir_prefix($urpm) . $< . "/lib";
    init_dir($urpm, $dir);
}

sub userdir {
    #mdkonline uses userdir because it runs as user
    my ($urpm) = @_;
    $< or return;

    my $dir = ($urpm->{urpmi_root} || '') . userdir_prefix($urpm) . $<;
    init_dir($urpm, $dir);
}

sub ensure_valid_cachedir {
    my ($urpm) = @_;
    if (my $dir = userdir($urpm)) {
	$urpm->{cachedir} = $dir;
    }
    -w "$urpm->{cachedir}/partial" or $urpm->{fatal}(1, N("Can not download packages into %s", "$urpm->{cachedir}/partial"));
}

sub valid_cachedir {
    my ($urpm) = @_;
    userdir($urpm) || $urpm->{cachedir};
}

sub is_temporary_file {
    my ($urpm, $f) = @_;

    begins_with($f, $urpm->{cachedir});
}

sub set_env {
    my ($urpm, $env) = @_;
    -d $env or $urpm->{fatal}(8, N("Environment directory %s does not exist", $env));
    print N("using specific environment on %s\n", $env);
    #- setting new environment.
    $urpm->{config} = "$env/urpmi.cfg";
    if (cat_($urpm->{config}) =~ /^\s*virtual\s*$/m) {
	print "dropping virtual from $urpm->{config}\n";
	system(q(perl -pi -e 's/^\s*virtual\s*$//' ) . $urpm->{config});
    }
    $urpm->{mediacfgdir} = "$env/mediacfg.d";
    $urpm->{skiplist} = "$env/skip.list";
    $urpm->{instlist} = "$env/inst.list";
    $urpm->{prefer_list} = "$env/prefer.list";
    $urpm->{prefer_vendor_list} = "$env/prefer.vendor.list";
    $urpm->{statedir} = $env;
    $urpm->{env_rpmdb} = "$env/rpmdb.cz";
    $urpm->{env_dir} = $env;
}

sub set_files {
    my ($urpm, $urpmi_root) = @_;

    $urpmi_root and $urpmi_root = file2absolute_file($urpmi_root);

    my %h = (
	config        => "$urpmi_root/etc/urpmi/urpmi.cfg",
	mediacfgdir   => "$urpmi_root/etc/urpmi/mediacfg.d",
	skiplist      => prefer_rooted($urpmi_root, '/etc/urpmi/skip.list'),
	instlist      => prefer_rooted($urpmi_root, '/etc/urpmi/inst.list'),
	prefer_list   => prefer_rooted($urpmi_root, '/etc/urpmi/prefer.list'),
	prefer_vendor_list => 
	                 prefer_rooted($urpmi_root, '/etc/urpmi/prefer.vendor.list'),
	private_netrc => "$urpmi_root/etc/urpmi/netrc",
	statedir      => "$urpmi_root/var/lib/urpmi",
	cachedir      => "$urpmi_root/var/cache/urpmi",
	root          => $urpmi_root,
	$urpmi_root ? (urpmi_root => $urpmi_root) : @{[]},
    );
    $urpm->{$_} = $h{$_} foreach keys %h;

    create_var_lib_rpm($urpm, %h);

   # policy is too use chroot environment only for --urpmi-root, not for --root:
    if ($urpmi_root && -e "$urpmi_root/etc/rpm/macros") {
	URPM::loadmacrosfile("$urpmi_root/etc/rpm/macros");
    }
}

sub create_var_lib_rpm {
    my ($urpm, %h) = @_;
    require File::Path;
    File::Path::mkpath([ $h{statedir}, 
			 (map { "$h{cachedir}/$_" } qw(partial rpms)),
			 dirname($h{config}),
			 "$urpm->{root}/var/lib/rpm",
			 "$urpm->{root}/var/tmp",
		     ]);
}

sub modify_rpm_macro {
    my ($name, $to_remove, $to_add) = @_;

    my $val = URPM::expand('%' . $name);
    $val =~ s/$to_remove/$to_add/ or $val = join(' ', grep { $_ } $val, $to_add);
    URPM::add_macro("$name $val");
}

sub set_tune_rpm {
    my ($urpm, $para) = @_;

    my %h = map { $_ => 1 } map { 
	if ($_ eq 'all') {
	    ('nofsync', 'private');
	} else {
	    $_;
	}
    } split(',', $para);

    $urpm->{tune_rpm} = \%h;
}

sub tune_rpm {
    my ($urpm) = @_;

    if ($urpm->{tune_rpm}{nofsync}) {
	modify_rpm_macro('__dbi_other', 'fsync', 'nofsync');
    }
    if ($urpm->{tune_rpm}{private}) {
	urpm::sys::clean_rpmdb_shared_regions($urpm->{root});
	modify_rpm_macro('__dbi_other', 'usedbenv', 'private');
    }
}

sub _blist_pkg_to_urls {
    my ($blist, @pkgs) = @_;
    my $base_url = $blist->{medium}{url} . '/';
    map { $base_url . $_->filename } @pkgs;
}
sub blist_pkg_to_url {
    my ($blist, $pkg) = @_;
    my ($url) = _blist_pkg_to_urls($blist, $pkg);
    $url;
}
sub blist_to_urls {
    my ($blist) = @_;
    _blist_pkg_to_urls($blist, values %{$blist->{pkgs}});
}
sub blist_to_filenames {
    my ($blist) = @_;
    map { $_->filename } values %{$blist->{pkgs}};
}

sub protocol_from_url {
    my ($url) = @_;
    $url =~ m!^(\w+)(_[^:]*)?:! && $1;
}
sub file_from_local_url {
    my ($url) = @_;
    $url =~ m!^(?:removable[^:]*:/|file:/)?(/.*)! && $1;
}
sub file_from_local_medium {
    my ($medium, $o_url) = @_;
    my $url = $o_url || $medium->{url};
    if ($url =~ m!^cdrom://(.*)!) {
	my $rel = $1;	
	$medium->{mntpoint} or do { require Carp; Carp::confess("cdrom is not mounted yet!\n") };
	"$medium->{mntpoint}/$rel";
    } else {
	file_from_local_url($url);
    }
}
sub is_local_url {
    my ($url) = @_;
    file_from_local_url($url) || is_cdrom_url($url);
}
sub is_local_medium {
    my ($medium) = @_;
    is_local_url($medium->{url});
}
sub is_cdrom_url {
    my ($url) = @_;
    protocol_from_url($url) eq 'cdrom';
}

=item db_open_or_die($urpm, $b_write_perm)

Open RPM database (RW or not) and die if it fails

=cut

sub db_open_or_die_ {
    my ($urpm, $b_write_perm) = @_;
    my $db;
    if ($urpm->{env_rpmdb}) {
	#- URPM has same methods as URPM::DB and empty URPM will be seen as empty URPM::DB.
        $db = URPM->new;
        $db->parse_synthesis($urpm->{env_rpmdb});
    } else {
	$db = db_open_or_die($urpm, $urpm->{root}, $b_write_perm);
    }
    $db;
}

# please use higher level function db_open_or_die_()
sub db_open_or_die {
    my ($urpm, $root, $b_write_perm) = @_;

    $urpm->{debug} and $urpm->{debug}("opening rpmdb (root=$root, write=$b_write_perm)");

    my $db = URPM::DB::open($root, $b_write_perm || 0)
      or $urpm->{fatal}(9, N("unable to open rpmdb"));

    $db;
}

=item register_rpms($urpm, @files)

Register local packages for being installed, keep track of source.

=cut

sub register_rpms {
    my ($urpm, @files) = @_;
    my ($start, $id, $error, %requested);

    #- examine each rpm and build the depslist for them using current
    #- depslist and provides environment.
    $start = @{$urpm->{depslist}};
    foreach (@files) {
	/\.(?:rpm|spec)$/ or $error = 1, $urpm->{error}(N("invalid rpm file name [%s]", $_)), next;

	#- if that's an URL, download.
	if (protocol_from_url($_)) {
	    my $basename = basename($_);
	    unlink "$urpm->{cachedir}/partial/$basename";
	    $urpm->{log}(N("retrieving rpm file [%s] ...", $_));
	    if (urpm::download::sync_url($urpm, $_, quiet => 1)) {
		$urpm->{log}(N("...retrieving done"));
		$_ = "$urpm->{cachedir}/partial/$basename";
	    } else {
		$urpm->{error}(N("...retrieving failed: %s", $@));
		unlink "$urpm->{cachedir}/partial/$basename";
		next;
	    }
	} else {