Project

General

Profile

« Previous | Next » 

Revision 4333564a

Added by Renato Botelho about 8 years ago

Fix indent and spaces

View differences:

src/etc/inc/pkg-utils.inc
337 337
}
338 338

  
339 339
// Get information about packages.
340
function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false, $installed_pkgs_only = false) {
341

  
340
function get_pkg_info($pkgs = 'all', $remote_repo_usage_disabled = false,
341
    $installed_pkgs_only = false) {
342 342
	global $g, $input_errors;
343 343

  
344 344
	$out = $err = $extra_param = '';
......
375 375
	}
376 376

  
377 377
	if (!$installed_pkgs_only) {
378
		$rc = pkg_exec("search {$extra_param}-R --raw-format json-compact " . $pkgs, $out, $err);
378
		$rc = pkg_exec(
379
		    "search {$extra_param}-R --raw-format json-compact " .
380
		    $pkgs, $out, $err);
379 381
	}
380
	if (($installed_pkgs_only || ($rc != 0 && $remote_repo_usage_disabled)) && is_pkg_installed($pkgs)) {
381
		/* Fall back on pkg info to return locally installed matching pkgs instead, if 
382
	if (($installed_pkgs_only || ($rc != 0 && $remote_repo_usage_disabled))
383
	    && is_pkg_installed($pkgs)) {
384
		/*
385
		 * Fall back on pkg info to return locally installed matching
386
		 * pkgs instead, if:
382 387
		 *
383 388
		 *   (1) only installed pkgs needed, or
384
		 *       we tried to check the local catalog copy (implying that we would have accepted incomplete/outdated pkg info)
385
		 *       but it didn't have any contents, or for other reasons returned an error. 
389
		 *       we tried to check the local catalog copy (implying that
390
		 *       we would have accepted incomplete/outdated pkg info)
391
		 *       but it didn't have any contents, or for other reasons
392
		 *       returned an error.
386 393
		 *   AND
387 394
		 *   (2) at least some pkgs matching <pattern> are installed
388 395
		 *
389
		 * Following an unsuccessful attempt to access a remote repo catalog, the local copy is wiped clear. Thereafter any
390
		 * "pkg search" will return an error until online+updated again. If the calling code would have accepted local copy info
391
		 * (which could be incomplete/out of date), then it makes sense to fall back on pkg info to at least return the known
392
		 * info about installed pkgs (pkg info should still work), instead of failing and returning no info at all. 
393
		 * For example, this at least enables offline view + management of installed pkgs in GUI/console.
396
		 * Following an unsuccessful attempt to access a remote repo
397
		 * catalog, the local copy is wiped clear. Thereafter any
398
		 * "pkg search" will return an error until online+updated again.
399
		 * If the calling code would have accepted local copy info
400
		 * (which could be incomplete/out of date), then it makes sense
401
		 * to fall back on pkg info to at least return the known
402
		 * info about installed pkgs (pkg info should still work),
403
		 * instead of failing and returning no info at all. 
404
		 * For example, this at least enables offline view + management
405
		 * of installed pkgs in GUI/console.
406
		 *
407
		 * We skip this step if no matching pkgs are installed, because
408
		 * then pkg info would return a "no matching pkgs" RC code,
409
		 * even though this wouldn't be considered an "error" (and
410
		 * $out+$err would be correct empty strings if none match).
394 411
		 *
395
		 * We skip this step if no matching pkgs are installed, because then pkg info would return a "no matching pkgs"
396
		 * RC code, even though this wouldn't be considered an "error" (and $out+$err would be correct empty strings if none match).
397
		 * Note that is_pkg_installed() is a wrapper for pkg info -e <pattern> which is what we need here.
412
		 * Note that is_pkg_installed() is a wrapper for pkg info -e
413
		 * <pattern> which is what we need here.
398 414
		*/
399 415
		
400 416
		// ok, 1 or more packages match, so pkg info can be safely called to get the pkg list  
401
		$rc = pkg_exec("info -R --raw-format json-compact " . $pkgs, $out, $err);  
417
		$rc = pkg_exec("info -R --raw-format json-compact " . $pkgs,
418
		    $out, $err);
402 419
	}
403 420

  
404 421
	if ($lock) {
......
410 427
		    "ERROR: Error trying to get packages list. Aborting...")
411 428
		    . "\n");
412 429
		update_status($err);
413
		$input_errors[] =  gettext("ERROR: Error trying to get packages list. Aborting...") . "\n";
414
		$input_errors[] =  $err;
430
		$input_errors[] = gettext(
431
		    "ERROR: Error trying to get packages list. Aborting...") .
432
		    "\n";
433
		$input_errors[] = $err;
415 434
		return array();
416 435
	}
417 436

  
......
423 442
			continue;
424 443
		}
425 444

  
426
		if (isset($pkg_filter) && !in_array($pkg_info['name'], $pkg_filter)) {
445
		if (isset($pkg_filter) && !in_array($pkg_info['name'],
446
		    $pkg_filter)) {
427 447
			continue;
428 448
		}
429 449

  
......
438 458
		if (is_pkg_installed($pkg_info['name'])) {
439 459
			$pkg_info['installed'] = true;
440 460

  
441
			$rc = pkg_exec("query %v {$pkg_info['name']}", $out, $err);
461
			$rc = pkg_exec("query %v {$pkg_info['name']}", $out,
462
			    $err);
442 463

  
443 464
			if ($rc != 0) {
444 465
				update_status("\n" . gettext(
445 466
				    "ERROR: Error trying to get package version. Aborting...")
446 467
				    . "\n");
447 468
				update_status($err);
448
				$input_errors[] =  gettext("ERROR: Error trying to get package version. Aborting...") . "\n";
449
				$input_errors[] =  $err;
469
				$input_errors[] = gettext(
470
				    "ERROR: Error trying to get package version. Aborting...") .
471
				    "\n";
472
				$input_errors[] = $err;
450 473
				return array();
451 474
			}
452 475

  
453
			$pkg_info['installed_version'] = str_replace("\n", "", $out);
476
			$pkg_info['installed_version'] = str_replace("\n", "",
477
			    $out);
454 478
		} else if (is_package_installed($pkg_info['shortname'])) {
455 479
			$pkg_info['broken'] = true;
456 480
		}
457 481

  
458
		$pkg_info['desc'] = preg_replace('/\n+WWW:.*$/', '', $pkg_info['desc']);
482
		$pkg_info['desc'] = preg_replace('/\n+WWW:.*$/', '',
483
		    $pkg_info['desc']);
459 484

  
460 485
		$result[] = $pkg_info;
461 486
		unset($pkg_info);

Also available in: Unified diff