Fix whitespace error: use of shlex.split instead of .split() (fix #2164)#2171
Merged
m3nu merged 1 commit intoborgbase:masterfrom Dec 16, 2024
Merged
Fix whitespace error: use of shlex.split instead of .split() (fix #2164)#2171m3nu merged 1 commit intoborgbase:masterfrom
m3nu merged 1 commit intoborgbase:masterfrom
Conversation
Contributor
|
Solid explanation! Thanks for looking into it and making a PR! |
m3nu
approved these changes
Dec 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As described in but #2164, Vorta/ borg raises an error when valid borg commands with whitespace are
provided via Vortas "Extra borg commands".
The issues arise when a folder/ filename contains whitespace.
The issue came up here: #2156 (reply in thread)
Related Issue
Extra borg arguments with white space raise an error #2164
Motivation and Context
See the following borg issue: borgbackup/borg#8578
There are different ways how borg can receive options (with folder/ name containing whitespace).
The following is a list of valid borg options - all of them raise an error in Vorta:
When investigating, I found that this issue is due to the use of standard python
.split()function in create.py.The
.split()function separates by whitespace - as a result, item names containing whitespace are split up:If this type of list is passed to Popen, 'folder' is treated as an attribute, which led to the error.
The solution for this type of error is the use of
shlex.split()instead of standard .split().Note that shlex.split is alredy used by Vorta, in other places, e.g. in /borg/borg_job.py
shlex.split()recognises the escaped whitespace in the item names, as required - the resulting attribute canbe passed to Popen as is.
When using
shlex.split(), one, minor, resulting issue is that the borg command (shell command) printed to the Vorta logs does not escape the whitespace, sinceshlex.split()removes the escape character.Since I wanted to provide a working borg command equivalent in the Vorta logs, I just added a additional step, where I replace whitespace by escaped whitespace (in the
cmdattributes) - before printing the borg commands to the logs.As a result, borg prints a command with escaped whitespaces (inside attributes only) that could be coppied/ run in the Shell.
An alternative would be to print the list of attributes, as is - but this does not lead to an easily readable borg command in the logs - that could be coppied/ pasted to the shell (a property I would like to keep)
How Has This Been Tested?
test folder"Checklist:
My change does not requires a change to the documentation.
I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.