Run archive_command through shell (#2766)

Close #2764
This commit is contained in:
Waynerv
2023-07-21 20:30:22 +08:00
committed by GitHub
parent cb9998ade6
commit 84c574e1ec
2 changed files with 6 additions and 2 deletions

View File

@@ -370,7 +370,7 @@ class Rewind(object):
# it is the author of archive_command, who is responsible
# for not overriding the WALs already present in archive
logger.info('Trying to archive %s: %s', wal, cmd)
if self._postgresql.cancellable.call(shlex.split(cmd)) == 0:
if self._postgresql.cancellable.call([cmd], shell=True) == 0:
new_name = os.path.join(status_dir, wal + '.done')
try:
shutil.move(old_name, new_name)

View File

@@ -239,7 +239,7 @@ class TestRewind(BaseTestPostgresql):
with patch('os.listdir', Mock(return_value=['000000000000000000000000.ready'])):
# successful archive_command call
with patch.object(CancellableSubprocess, 'call', Mock(return_value=0)):
with patch.object(CancellableSubprocess, 'call', Mock(return_value=0)) as mock_subprocess_call:
get_guc_value_res = [
'on', 'command %f',
'always', 'command %f',
@@ -252,6 +252,10 @@ class TestRewind(BaseTestPostgresql):
'000000000000000000000000', 'command 000000000000000000000000'),
mock_logger_info.call_args[0])
mock_logger_info.reset_mock()
mock_subprocess_call.assert_called_once()
self.assertEqual(mock_subprocess_call.call_args.args[0], ['command 000000000000000000000000'])
self.assertEqual(mock_subprocess_call.call_args.kwargs['shell'], True)
mock_subprocess_call.reset_mock()
# failed archive_command call
with patch.object(CancellableSubprocess, 'call', Mock(return_value=1)):