[diffoscope] 01/01: comparators/device: don't crash when comparing a non-device against a device

Mattia Rizzolo mattia at debian.org
Thu Jan 5 14:42:13 CET 2017


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository diffoscope.

commit d0d09d51833ff02fb8d9b9c4385415adf7b06346
Author: Maria Glukhova <siamezzze at gmail.com>
Date:   Tue Jan 3 20:52:16 2017 +0300

    comparators/device: don't crash when comparing a non-device against a device
    
    Wrap comparison in has_some_content_as in try..except and
    just assume they are different on errors.
    
    Gbp-Dch: Short
    Closes: #850055
    Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
 diffoscope/comparators/device.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/diffoscope/comparators/device.py b/diffoscope/comparators/device.py
index 273e28a..e9f2385 100644
--- a/diffoscope/comparators/device.py
+++ b/diffoscope/comparators/device.py
@@ -19,6 +19,7 @@
 
 import os
 import stat
+import logging
 
 from diffoscope.tempfiles import get_named_temporary_file
 from diffoscope.difference import Difference
@@ -26,6 +27,8 @@ from diffoscope.difference import Difference
 from .binary import FilesystemFile
 from .utils.file import File
 
+logger = logging.getLogger(__name__)
+
 
 class Device(File):
     @staticmethod
@@ -38,7 +41,12 @@ class Device(File):
         return st.st_mode, os.major(st.st_rdev), os.minor(st.st_rdev)
 
     def has_same_content_as(self, other):
-        return self.get_device() == other.get_device()
+        logging.debug('Device.has_same_content: %s %s', self, other)
+        try:
+            return self.get_device() == other.get_device()
+        except (AttributeError, OSError):
+            # 'other' is not a device, or something.
+            return False
 
     def create_placeholder(self):
         with get_named_temporary_file(mode='w+', delete=False) as f:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list