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

Fix: Invalid escape sequences #1352

Merged
merged 1 commit into from
Nov 4, 2022
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
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version 1.3.3-dev (development of upcoming release)
* GUI change: Define accelerator keys for menu bar and tabs, as well as toolbar shortcuts (#1104)
* Desktop integration: Update .desktop file to mark Back In Time as a single main window program (#1258)
* Improvement: Write all log output to stderr; do not pollute stdout with INFO and WARNING messages anymore (#1337)
* Bugfix: DeprecationWarnings about invalid escape sequences.
* Bugfix: AttributeError in "Diff Options" dialog (#898)
* Bugfix: Settings GUI: "Save password to Keyring" was disabled due to "no appropriate keyring found" (#1321)
* Bugfix: Back in Time did not start with D-Bus error
Expand Down
2 changes: 1 addition & 1 deletion common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Config(configfile.ConfigFileWithProfiles):
DEFAULT_RUN_IONICE_ON_REMOTE = False
DEFAULT_RUN_NOCACHE_ON_LOCAL = False
DEFAULT_RUN_NOCACHE_ON_REMOTE = False
DEFAULT_SSH_PREFIX = 'PATH=/opt/bin:/opt/sbin:\$PATH'
DEFAULT_SSH_PREFIX = 'PATH=/opt/bin:/opt/sbin:\\$PATH'
DEFAULT_REDIRECT_STDOUT_IN_CRON = True
DEFAULT_REDIRECT_STDERR_IN_CRON = False

Expand Down
17 changes: 10 additions & 7 deletions common/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def restore(self,
restore to original destiantion
delete (bool): delete newer files which are not in the
snapshot
backup (bool): create backup files (\*.backup.YYYYMMDD)
backup (bool): create backup files (*.backup.YYYYMMDD)
before changing or deleting local files.
only_new (bool): Only restore files which does not exist
or are newer than those in destination.
Expand Down Expand Up @@ -1405,22 +1405,25 @@ def smartRemove(self, del_snapshots, log = None):
additionalChars = len(self.config.sshPrefixCmd(cmd_type = str))

head = 'screen -d -m bash -c "('
head += 'TMP=\$(mktemp -d); ' #create temp dir used for delete files with rsync
head += 'test -z \\\"\$TMP\\\" && exit 1; ' #make sure $TMP dir was created
head += 'test -n \\\"\$(ls \$TMP)\\\" && exit 1; ' #make sure $TMP is empty
# create temp dir used for delete files with rsync
head += 'TMP=\\$(mktemp -d); '
# make sure $TMP dir was created
head += 'test -z \\\"\\$TMP\\\" && exit 1; '
# make sure $TMP is empty
head += 'test -n \\\"\\$(ls \\$TMP)\\\" && exit 1; '
Comment on lines -1408 to +1413
Copy link
Member Author

@buhtz buhtz Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry the diff here is hard to see.
In all three lines the \$ was modified to \\$.

if logger.DEBUG:
head += 'logger -t \\\"backintime smart-remove [$BASHPID]\\\" \\\"start\\\"; '
head += 'flock -x 9; '
if logger.DEBUG:
head += 'logger -t \\\"backintime smart-remove [$BASHPID]\\\" \\\"got exclusive flock\\\"; '

tail = 'rmdir \$TMP) 9>\\\"%s\\\""' %lckFile
tail = 'rmdir \\$TMP) 9>\\\"%s\\\""' %lckFile

cmds = []
for sid in del_snapshots:
remote = self.rsyncRemotePath(sid.path(use_mode = ['ssh', 'ssh_encfs']), use_mode = [], quote = '\\\"')
rsync = ' '.join(tools.rsyncRemove(self.config, run_local = False))
rsync += ' \\\"\$TMP/\\\" {}; '.format(remote)
rsync += ' \\\"\\$TMP/\\\" {}; '.format(remote)

s = 'test -e \\\"%s\\\" && (' %sid.path(use_mode = ['ssh', 'ssh_encfs'])
if logger.DEBUG:
Expand Down Expand Up @@ -1634,7 +1637,7 @@ def statFreeSpaceSsh(self):
# /tmp 127266564 115596412 5182296 96% /
# ^^^^^^^
for line in output.split(b'\n'):
m = re.match(b'^.*?\s+\d+\s+\d+\s+(\d+)\s+\d+%', line, re.M)
m = re.match(r'^.*?\s+\d+\s+\d+\s+(\d+)\s+\d+%', line.decode(), re.M)
Comment on lines -1637 to +1640
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output from shell was catched as binary instead of a string. No need for that.
Converted that to a real string (via .decode()) and run a raw regex string (via r'') on it.


if m:
return int(int(m.group(1)) / 1024)
Expand Down
2 changes: 1 addition & 1 deletion common/sshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def maxArg():
cmd += 'test $err_flock -ne 0 && cleanup $err_flock; '
tail.append(cmd)

cmd = 'echo \"rmdir \$(mktemp -d)\"; tmp3=$(mktemp -d); test -z "$tmp3" && cleanup 1; rmdir $tmp3 >/dev/null; err_rmdir=$?; '
cmd = 'echo \"rmdir \\$(mktemp -d)\"; tmp3=$(mktemp -d); test -z "$tmp3" && cleanup 1; rmdir $tmp3 >/dev/null; err_rmdir=$?; '
cmd += 'test $err_rmdir -ne 0 && cleanup $err_rmdir; '
tail.append(cmd)

Expand Down