Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#3330] Fix logic leading to creation of PGPASSFILE when connecting t… #3480

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions includes/filesystem.inc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ function drush_mkdir($path) {
function drush_program_exists($program) {
if (drush_has_bash()) {
$bucket = drush_bit_bucket();

// Remove environment variables (eg. PGPASSFILE=) before testing program.
$program = preg_replace('#^([A-Z0-9]+=.+? )+#', '', $program);

// Dont't use drush_op_system() since we don't want output during tests.
system("command -v $program > $bucket 2>&1", $result_code);
return $result_code === 0 ? TRUE : FALSE;
Expand Down
17 changes: 11 additions & 6 deletions src/Sql/SqlPgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class SqlPgsql extends SqlBase

private function createPasswordFile()
{
$password_file = null;
$dbSpec = $this->getDbSpec();
if (null !== ($this->getPasswordFile()) && isset($dbSpec['password'])) {
if (null == ($this->getPasswordFile()) && isset($dbSpec['password'])) {
$pgpass_parts = [
empty($dbSpec['host']) ? 'localhost' : $dbSpec['host'],
empty($dbSpec['port']) ? '5432' : $dbSpec['port'],
Expand All @@ -34,10 +33,10 @@ private function createPasswordFile()
$part = str_replace(['\\', ':'], ['\\\\', '\:'], $part);
});
$pgpass_contents = implode(':', $pgpass_parts);
$password_file = drush_save_data_to_temp_file($pgpass_contents);
chmod($password_file, 0600);
$this->password_file = drush_save_data_to_temp_file($pgpass_contents);
chmod($this->password_file, 0600);
}
return $password_file;
return $this->password_file;
}

public function command()
Expand Down Expand Up @@ -128,7 +127,13 @@ public function dumpCmd($table_selection)
$data_only = $this->getOption('data-only');

$create_db = $this->getOption('create-db');
$exec = 'pg_dump ';

$environment = "";
$pw_file = $this->createPasswordFile();
if (isset($pw_file)) {
$environment = "PGPASSFILE={$pw_file} ";
}
$exec = "{$environment}pg_dump ";
// Unlike psql, pg_dump does not take a '--dbname=' before the database name.
$extra = str_replace('--dbname=', ' ', $this->creds());
if (isset($data_only)) {
Expand Down