[Reproducible-commits] [diffoscope] 10/13: Don't recognize .dsc and .changes when referenced files are missing
Jérémy Bobbio
lunar at moszumanska.debian.org
Thu Oct 15 16:04:35 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit 27d00b3972397c33ac9df4f67a319bb98ad15ead
Author: Jérémy Bobbio <lunar at debian.org>
Date: Thu Oct 15 13:32:21 2015 +0000
Don't recognize .dsc and .changes when referenced files are missing
We used to crash when .changes were referencing non-existing files. Now they
will be recognized as text. We also behave the same for .dsc.
This ask the question on what to do for .dsc and .changes files inside
archives. But for now, this is already better than it was.
---
diffoscope/comparators/debian.py | 21 +++++++++++++++++++--
tests/comparators/test_debian.py | 18 ++++++++++++++++--
tests/data/test1.debsrc.tar.gz | Bin 0 -> 2086 bytes
tests/data/test1.dsc | 16 ++++++++++++++++
tests/data/test2.debsrc.tar.gz | Bin 0 -> 2193 bytes
tests/data/test2.dsc | 16 ++++++++++++++++
6 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index d315560..a361e5d 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -18,6 +18,8 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
from contextlib import contextmanager
+from functools import partial
+import hashlib
import os.path
import re
from debian.deb822 import Dsc
@@ -142,7 +144,10 @@ class DotChangesFile(DebControlFile):
return False
with file.get_content():
changes = Changes(filename=file.path)
- changes.validate(check_signature=False)
+ try:
+ changes.validate(check_signature=False)
+ except FileNotFoundError:
+ return False
file._deb822 = changes
return True
@@ -155,5 +160,17 @@ class DotDscFile(DebControlFile):
return False
with file.get_content():
with open(file.path, 'rb') as f:
- file._deb822 = Dsc(f)
+ dsc = Dsc(f)
+ for d in dsc.get('Files'):
+ md5 = hashlib.md5()
+ # XXX: this will not work for containers
+ in_dsc_path = os.path.join(os.path.dirname(file.path), d['Name'])
+ if not os.path.exists(in_dsc_path):
+ return False
+ with open(in_dsc_path, 'rb') as f:
+ for buf in iter(partial(f.read, 32768), b''):
+ md5.update(buf)
+ if md5.hexdigest() != d['md5sum']:
+ return False
+ file._deb822 = dsc
return True
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index f46e344..c248879 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -31,8 +31,6 @@ TEST_DOT_CHANGES_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/t
TEST_DEB_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.deb')
TEST_DEB_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.deb')
-# XXX: test validate failure
-
@pytest.fixture
def dot_changes1(tmpdir):
tmpdir.mkdir('a')
@@ -52,6 +50,14 @@ def dot_changes2(tmpdir):
def test_dot_changes_identification(dot_changes1):
assert isinstance(dot_changes1, DotChangesFile)
+def test_dot_changes_invalid(tmpdir):
+ tmpdir.mkdir('a')
+ dot_changes_path = str(tmpdir.join('a/test_1.changes'))
+ shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_changes_path)
+ # we don't copy the referenced .deb
+ identified = specialize(FilesystemFile(dot_changes_path))
+ assert not isinstance(identified, DotChangesFile)
+
def test_dot_changes_no_differences(dot_changes1):
difference = dot_changes1.compare(dot_changes1)
assert difference is None
@@ -101,6 +107,14 @@ def dot_dsc2(tmpdir):
def test_dot_dsc_identification(dot_dsc1):
assert isinstance(dot_dsc1, DotDscFile)
+def test_dot_dsc_invalid(tmpdir, dot_dsc2):
+ tmpdir.mkdir('a')
+ dot_dsc_path = str(tmpdir.join('a/test_1.dsc'))
+ shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_dsc_path)
+ # we don't copy the referenced .tar.gz
+ identified = specialize(FilesystemFile(dot_dsc_path))
+ assert not isinstance(identified, DotDscFile)
+
def test_dot_dsc_no_differences(dot_dsc1):
difference = dot_dsc1.compare(dot_dsc1)
assert difference is None
diff --git a/tests/data/test1.debsrc.tar.gz b/tests/data/test1.debsrc.tar.gz
new file mode 100644
index 0000000..6216be1
Binary files /dev/null and b/tests/data/test1.debsrc.tar.gz differ
diff --git a/tests/data/test1.dsc b/tests/data/test1.dsc
new file mode 100644
index 0000000..96d997d
--- /dev/null
+++ b/tests/data/test1.dsc
@@ -0,0 +1,16 @@
+Format: 1.0
+Source: test
+Binary: test
+Architecture: all
+Version: 1
+Maintainer: Someone Else <user at example.org>
+Standards-Version: 3.9.6
+Build-Depends: debhelper (>= 7)
+Package-List:
+ test deb misc optional
+Checksums-Sha1:
+ 2f66c0cf9788240c8c3321193d4a628157748445 2086 test_1.tar.gz
+Checksums-Sha256:
+ 1066cb6c1fca0423eb449b7aac27d5a477c55f4262ab8af438100a6d2ee039b4 2086 test_1.tar.gz
+Files:
+ 42c53394ba8bb4d92aab8d40d33507d7 2086 test_1.tar.gz
diff --git a/tests/data/test2.debsrc.tar.gz b/tests/data/test2.debsrc.tar.gz
new file mode 100644
index 0000000..400f3b6
Binary files /dev/null and b/tests/data/test2.debsrc.tar.gz differ
diff --git a/tests/data/test2.dsc b/tests/data/test2.dsc
new file mode 100644
index 0000000..29b0253
--- /dev/null
+++ b/tests/data/test2.dsc
@@ -0,0 +1,16 @@
+Format: 1.0
+Source: test
+Binary: test
+Architecture: all
+Version: 1
+Maintainer: Someone Else <user at example.org>
+Standards-Version: 3.9.6
+Build-Depends: debhelper (>= 7)
+Package-List:
+ test deb misc optional
+Checksums-Sha1:
+ 7453b45105d06be451cbc472c2fa1df13a60eb27 2193 test_1.tar.gz
+Checksums-Sha256:
+ ff86b4d705489ee0f2825a935100f9a0981b6c8c4c0eb5e19436c8599da14324 2193 test_1.tar.gz
+Files:
+ b75f3bae96326e1c518dba429a81f91c 2193 test_1.tar.gz
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list