Просмотр исходного кода

multicompress with externals sets wrong file modes

Copy from the bug description:
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.

[Original testcase slightly modified to comply with house-style]

Closes: 737130
Colin Watson лет назад: 12
Родитель
Сommit
cc130d7114

+ 1 - 1
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"),

+ 30 - 0
test/integration/test-bug-737130-multicompress-file-modes

@@ -0,0 +1,30 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+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
+testsuccess aptftparchive generate aptarchive/ftparchive.conf
+i18n=aptarchive/dists/sid/main/i18n
+for comp in '' .gz .bz2 .xz; do
+	msgtest 'Test apt-ftparchive file mode is 644 for' "Translation-en$comp"
+	FILEMODE="$(stat --format %a "$i18n/Translation-en$comp")"
+	if [ "$FILEMODE" != '644' ]; then
+		msgfail "Mode was '$FILEMODE'!"
+	else
+		msgpass
+	fi
+done