Browse Source

Merge remote-tracking branch 'mvo/debian/sid' into debian/sid

Michael Vogt 12 years ago
parent
commit
a78578a9bf

+ 9 - 6
cmdline/apt-extracttemplates.cc

@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <unistd.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 
 #include "apt-extracttemplates.h"
 #include "apt-extracttemplates.h"
 
 
@@ -239,23 +240,25 @@ static int ShowHelp(void)
 static string WriteFile(const char *package, const char *prefix, const char *data)
 static string WriteFile(const char *package, const char *prefix, const char *data)
 {
 {
 	char fn[512];
 	char fn[512];
-	static int i;
 
 
         std::string tempdir = GetTempDir();
         std::string tempdir = GetTempDir();
-	snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
+	snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX",
                  _config->Find("APT::ExtractTemplates::TempDir", 
                  _config->Find("APT::ExtractTemplates::TempDir", 
                                tempdir.c_str()).c_str(),
                                tempdir.c_str()).c_str(),
-                 package, prefix, getpid(), i++);
+                 package, prefix);
 	FileFd f;
 	FileFd f;
 	if (data == NULL)
 	if (data == NULL)
 		data = "";
 		data = "";
-
-	if (!f.Open(fn, FileFd::WriteTemp, 0600))
+        int fd = mkstemp(fn);
+        if (fd < 0) {
+		_error->Errno("ofstream::ofstream",_("Unable to mkstemp %s"),fn);
+                return string();
+        }
+	if (!f.OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
 	{
 	{
 		_error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
 		_error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
 		return string();
 		return string();
 	}
 	}
-
 	f.Write(data, strlen(data));
 	f.Write(data, strlen(data));
 	f.Close();
 	f.Close();
 	return fn;
 	return fn;

+ 1 - 1
debian/apt.cron.daily

@@ -41,7 +41,7 @@
 #  APT::Periodic::MaxSize "0"; (new)
 #  APT::Periodic::MaxSize "0"; (new)
 #  - Set maximum size of the cache in MB (0=disable). If the cache
 #  - Set maximum size of the cache in MB (0=disable). If the cache
 #    is bigger, cached package files are deleted until the size
 #    is bigger, cached package files are deleted until the size
-#    requirement is met (the biggest packages will be deleted 
+#    requirement is met (the oldest packages will be deleted 
 #    first).
 #    first).
 #
 #
 #  APT::Periodic::Update-Package-Lists "0";
 #  APT::Periodic::Update-Package-Lists "0";

+ 2 - 2
doc/apt-extracttemplates.1.xml

@@ -47,8 +47,8 @@
    <para>template-file and config-script are written to the temporary directory
    <para>template-file and config-script are written to the temporary directory
    specified by the <option>-t</option> or <option>--tempdir</option>
    specified by the <option>-t</option> or <option>--tempdir</option>
    (<literal>APT::ExtractTemplates::TempDir</literal>) directory,
    (<literal>APT::ExtractTemplates::TempDir</literal>) directory,
-   with filenames of the form <filename>package.template.XXXX</filename> and
-   <filename>package.config.XXXX</filename></para>
+   with filenames of the form <filename>package.template.XXXXXX</filename> and
+   <filename>package.config.XXXXXX</filename></para>
  </refsect1>
  </refsect1>
  
  
  <refsect1><title>options</title>
  <refsect1><title>options</title>

+ 1 - 1
doc/examples/configure-index

@@ -149,7 +149,7 @@ APT
     MaxSize "0"; // (new)
     MaxSize "0"; // (new)
     // - Set maximum size of the cache in MB (0=disable). If the cache
     // - Set maximum size of the cache in MB (0=disable). If the cache
     //   is bigger, cached package files are deleted until the size
     //   is bigger, cached package files are deleted until the size
-    //   requirement is met (the biggest packages will be deleted 
+    //   requirement is met (the oldest packages will be deleted 
     //   first).
     //   first).
 
 
     Update-Package-Lists "0";
     Update-Package-Lists "0";

+ 1 - 0
test/integration/framework

@@ -118,6 +118,7 @@ apt() { runapt apt "$@"; }
 apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
 apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
 aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
 aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
 aptitude() { runapt aptitude "$@"; }
 aptitude() { runapt aptitude "$@"; }
+aptextracttemplates() { runapt apt-extracttemplates "$@"; }
 
 
 dpkg() {
 dpkg() {
 	command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
 	command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"

+ 45 - 0
test/integration/test-apt-extracttemplates

@@ -0,0 +1,45 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture 'amd64'
+
+# apt-extracttemplates needs this
+insertinstalledpackage 'debconf' 'amd64' '1.5'
+insertinstalledpackage 'pkg-with-template' 'amd64' '1.0'
+
+# build a simple package that contains a config and a tempalte
+mkdir -p DEBIAN
+TEMPLATE_STR="Template: foo/bar
+Type: string
+Description: Some bar var
+"
+echo "$TEMPLATE_STR" > DEBIAN/templates
+
+CONFIG_STR="#!/bin/sh
+random shell stuff
+"
+echo "$CONFIG_STR" > DEBIAN/config
+
+buildsimplenativepackage 'pkg-with-template' 'amd64' '0.8.15' 'stable' '' 'pkg with template' '' '' './DEBIAN' 
+
+# ensure we get the right stuff out of the file
+mkdir extracttemplates-out
+OUT="$(aptextracttemplates -t ./extracttemplates-out incoming/pkg-with-template*.deb)"
+
+PKG=$(printf "$OUT" | cut -f1 -d' ')
+INSTALLED_VER=$(printf "$OUT" | cut -f2 -d' ')
+TEMPLATE=$(printf "$OUT" | cut -f3 -d' ')
+CONFIG=$(printf "$OUT" | cut -f4 -d' ')
+
+testequal "$CONFIG_STR" cat $CONFIG
+testequal "$TEMPLATE_STR" cat $TEMPLATE
+
+# ensure that the format of the output string has the right number of dots
+for s in "$CONFIG" "$TEMPLATE"; do
+    NR_DOTS=$(basename "$s" | tr -c -d .)
+    testequal ".." echo $NR_DOTS
+done