[Reproducible-commits] [diffoscope] 01/01: Stop unpacking Tar directories
Jérémy Bobbio
lunar at moszumanska.debian.org
Thu Sep 3 14:56:45 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 b532fb06ce078c029c60be0e26e41bc2e1b0b457
Author: Jérémy Bobbio <lunar at debian.org>
Date: Thu Sep 3 14:49:13 2015 +0000
Stop unpacking Tar directories
Thanks NetBSD for making tarballs with unwritable directory and h01ger for the
report.
Closes: #797164
---
diffoscope/comparators/tar.py | 5 +++++
tests/comparators/test_tar.py | 12 ++++++++++++
tests/comparators/test_utils.py | 2 +-
tests/data/no-perms.tar | Bin 0 -> 10240 bytes
4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/diffoscope/comparators/tar.py b/diffoscope/comparators/tar.py
index 6cd0fc8..f08adf9 100644
--- a/diffoscope/comparators/tar.py
+++ b/diffoscope/comparators/tar.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
+from contextlib import contextmanager
import os.path
import re
import stat
@@ -52,6 +53,10 @@ class TarDirectory(Directory, TarMember):
def has_same_content_as(self, other):
return False
+ @contextmanager
+ def get_content(self):
+ yield
+
def is_directory(self):
return True
diff --git a/tests/comparators/test_tar.py b/tests/comparators/test_tar.py
index b68af14..bfab69a 100644
--- a/tests/comparators/test_tar.py
+++ b/tests/comparators/test_tar.py
@@ -69,3 +69,15 @@ def test_compare_non_existing(monkeypatch, tar1):
difference = tar1.compare(NonExistingFile('/nonexisting', tar1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
+
+ at pytest.fixture
+def no_permissions_tar():
+ return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/no-perms.tar')))
+
+# Reported as Debian #797164. This is a good way to notice if we unpack directories
+# as we won't be able to remove files in one if we don't have write permissions.
+def test_no_permissions_dir_in_tarball(monkeypatch, no_permissions_tar):
+ # We want to make sure OSError is not raised.
+ # Comparing with non-existing file makes it easy to make sure all files are unpacked
+ monkeypatch.setattr(Config, 'new_file', True)
+ no_permissions_tar.compare(NonExistingFile('/nonexistent', no_permissions_tar))
diff --git a/tests/comparators/test_utils.py b/tests/comparators/test_utils.py
index da70510..6dda4e0 100644
--- a/tests/comparators/test_utils.py
+++ b/tests/comparators/test_utils.py
@@ -22,7 +22,7 @@ import codecs
import os.path
import pytest
from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile
+from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.config import Config
@pytest.fixture
diff --git a/tests/data/no-perms.tar b/tests/data/no-perms.tar
new file mode 100644
index 0000000..da106ee
Binary files /dev/null and b/tests/data/no-perms.tar differ
--
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