From eb91bebe5273deaa79df33777519aa2e0d3a2bf4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 29 Jan 2017 21:13:07 +0200 Subject: Forbid restoring without absolute paths --- obnamlib/plugins/restore_plugin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/obnamlib/plugins/restore_plugin.py b/obnamlib/plugins/restore_plugin.py index b7944946..bf539b5f 100644 --- a/obnamlib/plugins/restore_plugin.py +++ b/obnamlib/plugins/restore_plugin.py @@ -33,6 +33,12 @@ class NoToError(obnamlib.ObnamError): msg = 'The restore command wants a target set with --to' +class RelativePathError(obnamlib.ObnamError): + + msg = ("Restore of {filename} requested, but it is not an absolute path " + "(doesn't start with /)") + + class RestoreErrors(obnamlib.ObnamError): msg = '''There were errors when restoring @@ -137,6 +143,10 @@ class RestorePlugin(obnamlib.ObnamPlugin): logging.debug('restoring to %s', self.app.settings['to']) logging.debug('restoring what: %s', repr(args)) + if args: + for arg in args: + if not os.path.isabs(arg): + raise RelativePathError(filename=arg) if not args: logging.debug('no args given, so restoring everything') args = ['/'] -- cgit v1.2.1