diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-17 20:34:50 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-17 20:34:50 +0000 |
commit | c5f5ea70d4fd2190f9ae08b0455f8a871f814bd4 (patch) | |
tree | 8988a7a32c7514f0561e37a756191907cc6062cc | |
parent | 3da87141807810cf235a1b074b38572427d41b50 (diff) | |
download | obnam-c5f5ea70d4fd2190f9ae08b0455f8a871f814bd4.tar.gz |
Fix parsing of filtered files
This bug was originally triggered by the test suite, because the
error message in the code had a typo. While looking for that I noticed
that the code that was parsing the code seemed fishy.
This is now cleaner. First of all, I split the error messages for
"unknown tag" and "no tag". Then I rewrote the loop that parses
so it is robust against error situations. Then I tweaked the yarn
test so it now works.
-rw-r--r-- | obnamlib/hooks.py | 27 | ||||
-rw-r--r-- | yarns/0060-encryption.yarn | 2 |
2 files changed, 22 insertions, 7 deletions
diff --git a/obnamlib/hooks.py b/obnamlib/hooks.py index 91baed3b..a8a98a00 100644 --- a/obnamlib/hooks.py +++ b/obnamlib/hooks.py @@ -73,7 +73,12 @@ class Hook(object): class MissingFilterError(obnamlib.ObnamError): - msg = 'Unknown filter tag enountered: {tagname}' + msg = 'Unknown filter tag: {tagname}' + + +class NoFilterTagError(obnamlib.ObnamError): + + msg = 'No filter tag found' class FilterHook(Hook): @@ -108,13 +113,23 @@ class FilterHook(Hook): raise NotImplementedError() def run_filter_read(self, data, *args, **kwargs): - tag, content = data.split("\0", 1) - while tag != "": + + def filter_next_tag(data): + split = data.split('\0', 1) + if len(split) == 1: + raise NoFilterTagError() + tag, remaining = split + if tag == '': + return False, remaining if tag not in self.bytag: raise MissingFilterError(tagname=repr(tag)) - data = self.bytag[tag].filter_read(content, *args, **kwargs) - tag, content = data.split("\0", 1) - return content + callback = self.bytag[tag] + return True, callback.filter_read(remaining, *args, **kwargs) + + more = True + while more: + more, data = filter_next_tag(data) + return data def run_filter_write(self, data, *args, **kwargs): tracing.trace('called') diff --git a/yarns/0060-encryption.yarn b/yarns/0060-encryption.yarn index dbdc4c1d..384d7a70 100644 --- a/yarns/0060-encryption.yarn +++ b/yarns/0060-encryption.yarn @@ -99,7 +99,7 @@ client, should not be able to access the data. GIVEN a user U3 calling themselves U1 WHEN user U3 attempts to restore their latest generation in repository R into X3 THEN the attempt failed with exit code 1 - AND the error message matches "Unknown filter tag encountered\|need more than 1 value to unpack" + AND the error message matches "R169C6X: Unknown filter tag\|R173AEX: No filter tag found" (The error message above indicates that there's a bug in Obnam, which is that the error message, when an encryption is not provided but the |