[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#737130: apt-ftparchive: multicompress sets wrong file modes on files written using an external compression program



Package: apt
Version: 0.9.15
Severity: normal
Tags: patch
User: ubuntu-devel@lists.ubuntu.com
Usertags: origin-ubuntu ubuntu-patch trusty

After we upgraded the Ubuntu master archive from lucid to precise, we
noticed that Translation-en.bz2 was being written with mode 0600 rather
than 0644, which broke our mirroring.  This is no longer reproducible as
such in unstable because apt now links against libbz2, but it's still
reproducible with xz; it happens because multicompress fchmods one end
of the compression pipe in this case rather than the target file.
Here's a patch with an integration test.

diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc
index 265fb1a..c1bd603 100644
--- a/ftparchive/multicompress.cc
+++ b/ftparchive/multicompress.cc
@@ -365,7 +365,7 @@ bool MultiCompress::Child(int const &FD)
    for (Files *I = Outputs; I != 0; I = I->Next)
    {
       // Set the correct file modes
-      fchmod(I->TmpFile.Fd(),Permissions);
+      chmod(I->TmpFile.Name().c_str(),Permissions);
       
       if (rename(I->TmpFile.Name().c_str(),I->Output.c_str()) != 0)
 	 _error->Errno("rename",_("Failed to rename %s to %s"),
diff --git a/test/integration/test-multicompress-modes b/test/integration/test-multicompress-modes
new file mode 100755
index 0000000..b118622
--- /dev/null
+++ b/test/integration/test-multicompress-modes
@@ -0,0 +1,30 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture "i386"
+
+msgtest 'Test apt-ftparchive with Translation-* file modes'
+cat >aptarchive/ftparchive.conf <<EOF
+Dir { ArchiveDir "$(pwd)/aptarchive"; CacheDir "$(pwd)/aptarchive"; };
+Default { Translation::Compress ". gzip bzip2 xz"; FileMode 0644; };
+tree "dists/sid" {
+	Sections "main";
+	Architectures "i386";
+	LongDescription "false";
+};
+EOF
+mkdir -p aptarchive/dists/sid/main/binary-i386
+mkdir -p aptarchive/dists/sid/main/i18n
+aptftparchive generate aptarchive/ftparchive.conf 2>/dev/null
+i18n=aptarchive/dists/sid/main/i18n
+ok=1
+for comp in '' .gz .bz2 .xz; do
+	if [ "$(stat --format %a "$i18n/Translation-en$comp")" != 644 ]; then
+		ok=0
+		break
+	fi
+done
+[ "$ok" = 1 ] && msgpass || msgfail

Thanks,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]


Reply to: