mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
backups: Remove incorrectly set buffer size during download
- Don't set bufsize to 1 while streaming backup download. This is only effective with text streams with universal_newline flag set. An actual buffer size of 1 is very inefficient and plain wrong. Leave the python default of io.DEFAULT_BUFFER_SIZE. - Minor simplification to argument passing. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
484992fe37
commit
623bbc87e8
@ -100,38 +100,35 @@ from plinth.errors import ActionError
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run(action, options=None, input=None, run_in_background=False,
|
||||
bufsize=None):
|
||||
def run(action, options=None, input=None, run_in_background=False):
|
||||
"""Safely run a specific action as the current user.
|
||||
|
||||
See actions._run for more information.
|
||||
"""
|
||||
return _run(action, options, input, run_in_background, False,
|
||||
bufsize=bufsize)
|
||||
return _run(action, options, input, run_in_background, False)
|
||||
|
||||
|
||||
def superuser_run(action, options=None, input=None, run_in_background=False,
|
||||
bufsize=None, log_error=True):
|
||||
log_error=True):
|
||||
"""Safely run a specific action as root.
|
||||
|
||||
See actions._run for more information.
|
||||
"""
|
||||
return _run(action, options, input, run_in_background, True,
|
||||
bufsize=bufsize, log_error=log_error)
|
||||
log_error=log_error)
|
||||
|
||||
|
||||
def run_as_user(action, options=None, input=None, run_in_background=False,
|
||||
bufsize=None, become_user=None):
|
||||
become_user=None):
|
||||
"""Run a command as a different user.
|
||||
|
||||
If become_user is None, run as current user.
|
||||
"""
|
||||
return _run(action, options, input, run_in_background, False, become_user,
|
||||
bufsize=bufsize)
|
||||
return _run(action, options, input, run_in_background, False, become_user)
|
||||
|
||||
|
||||
def _run(action, options=None, input=None, run_in_background=False,
|
||||
run_as_root=False, become_user=None, log_error=True, bufsize=None):
|
||||
run_as_root=False, become_user=None, log_error=True):
|
||||
"""Safely run a specific action as a normal user or root.
|
||||
|
||||
Actions are pulled from the actions directory.
|
||||
@ -196,8 +193,7 @@ def _run(action, options=None, input=None, run_in_background=False,
|
||||
if cfg.develop:
|
||||
# In development mode pass on local pythonpath to access Plinth
|
||||
kwargs['env'] = {'PYTHONPATH': cfg.root}
|
||||
if bufsize is not None:
|
||||
kwargs['bufsize'] = bufsize
|
||||
|
||||
proc = subprocess.Popen(cmd, **kwargs)
|
||||
|
||||
if not run_in_background:
|
||||
|
||||
@ -139,9 +139,7 @@ class BorgRepository(object):
|
||||
archive_path = self.get_archive_path(archive_name)
|
||||
args = ['export-tar', '--path', archive_path]
|
||||
args = self.append_encryption_passphrase(args, self.credentials)
|
||||
kwargs = {'run_in_background': True,
|
||||
'bufsize': 1}
|
||||
proc = self._run('backups', args, kwargs=kwargs)
|
||||
proc = self._run('backups', args, run_in_background=True)
|
||||
return zipstream.ZipStream(proc.stdout, 'readline')
|
||||
|
||||
def get_archive(self, name):
|
||||
@ -166,15 +164,13 @@ class BorgRepository(object):
|
||||
def get_archive_path(self, archive_name):
|
||||
return "::".join([self.repo_path, archive_name])
|
||||
|
||||
def _run(self, cmd, arguments, superuser=True, kwargs=None):
|
||||
def _run(self, cmd, arguments, superuser=True, **kwargs):
|
||||
"""Run a backups or sshfs action script command."""
|
||||
if kwargs is None:
|
||||
kwargs = {}
|
||||
try:
|
||||
if superuser:
|
||||
return actions.superuser_run(cmd, arguments, **kwargs)
|
||||
else:
|
||||
return actions.run(cmd, arguments, **kwargs)
|
||||
|
||||
return actions.run(cmd, arguments, **kwargs)
|
||||
except ActionError as err:
|
||||
self.reraise_known_error(err)
|
||||
|
||||
@ -293,7 +289,7 @@ class SshBorgRepository(BorgRepository):
|
||||
self._path]
|
||||
arguments, kwargs = self._append_sshfs_arguments(arguments,
|
||||
self.credentials)
|
||||
self._run('sshfs', arguments, kwargs=kwargs)
|
||||
self._run('sshfs', arguments, **kwargs)
|
||||
|
||||
def umount(self):
|
||||
if not self.is_mounted:
|
||||
@ -314,14 +310,16 @@ class SshBorgRepository(BorgRepository):
|
||||
except Exception as err:
|
||||
logger.error(err)
|
||||
|
||||
def _append_sshfs_arguments(self, arguments, credentials, kwargs=None):
|
||||
def _append_sshfs_arguments(self, arguments, credentials):
|
||||
"""Add credentials to a run command and kwargs"""
|
||||
if kwargs is None:
|
||||
kwargs = {}
|
||||
kwargs = {}
|
||||
|
||||
if 'ssh_password' in credentials and credentials['ssh_password']:
|
||||
kwargs['input'] = credentials['ssh_password'].encode()
|
||||
|
||||
if 'ssh_keyfile' in credentials and credentials['ssh_keyfile']:
|
||||
arguments += ['--ssh-keyfile', credentials['ssh_keyfile']]
|
||||
|
||||
return (arguments, kwargs)
|
||||
|
||||
def run(self, arguments, superuser=True):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user