]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
pkgTagFile: if we have seen the end, do not try to see more
[apt.git] / apt-pkg / contrib / fileutl.cc
index d2be276c71a6eeaa9969b038e024fab573349fd7..37155b688173c2c25bc92f043867da53caf1a3e1 100644 (file)
@@ -319,7 +319,7 @@ bool CreateDirectory(string const &Parent, string const &Path)
       return false;
 
    // we are not going to create directories "into the blue"
-   if (Path.find(Parent, 0) != 0)
+   if (Path.compare(0, Parent.length(), Parent) != 0)
       return false;
 
    vector<string> const dirs = VectorizeString(Path.substr(Parent.size()), '/');
@@ -465,7 +465,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
       const char *C = Ent->d_name;
       for (; *C != 0; ++C)
         if (isalpha(*C) == 0 && isdigit(*C) == 0
-            && *C != '_' && *C != '-') {
+            && *C != '_' && *C != '-' && *C != ':') {
            // no required extension -> dot is a bad character
            if (*C == '.' && Ext.empty() == false)
               continue;
@@ -760,16 +760,13 @@ bool WaitFd(int Fd,bool write,unsigned long timeout)
    return true;
 }
                                                                        /*}}}*/
-// ExecFork - Magical fork that sanitizes the context before execing   /*{{{*/
+// MergeKeepFdsFromConfiguration - Merge APT::Keep-Fds configuration   /*{{{*/
 // ---------------------------------------------------------------------
-/* This is used if you want to cleanse the environment for the forked 
-   child, it fixes up the important signals and nukes all of the fds,
  otherwise acts like normal fork. */
-pid_t ExecFork()
+/* This is used to merge the APT::Keep-Fds with the provided KeepFDs
+ * set.
+ */
+void MergeKeepFdsFromConfiguration(std::set<int> &KeepFDs)
 {
-      set<int> KeepFDs;
-
-      // FIXME: remove looking at APT::Keep-Fds eventually, its a hack
       Configuration::Item const *Opts = _config->Tree("APT::Keep-Fds");
       if (Opts != 0 && Opts->Child != 0)
       {
@@ -782,6 +779,19 @@ pid_t ExecFork()
            KeepFDs.insert(fd);
         }
       }
+}
+                                                                       /*}}}*/
+// ExecFork - Magical fork that sanitizes the context before execing   /*{{{*/
+// ---------------------------------------------------------------------
+/* This is used if you want to cleanse the environment for the forked 
+   child, it fixes up the important signals and nukes all of the fds,
+   otherwise acts like normal fork. */
+pid_t ExecFork()
+{
+      set<int> KeepFDs;
+      // we need to merge the Keep-Fds as external tools like 
+      // debconf-apt-progress use it
+      MergeKeepFdsFromConfiguration(KeepFDs);
       return ExecFork(KeepFDs);
 }
 
@@ -1535,6 +1545,9 @@ bool FileFd::Skip(unsigned long long Over)
 /* */
 bool FileFd::Truncate(unsigned long long To)
 {
+   // truncating /dev/null is always successful - as we get an error otherwise
+   if (To == 0 && FileName == "/dev/null")
+      return true;
 #if defined HAVE_ZLIB || defined HAVE_BZ2
    if (d != NULL && (d->gz != NULL || d->bz2 != NULL))
       return FileFdError("Truncating compressed files is not implemented (%s)", FileName.c_str());
@@ -1814,3 +1827,20 @@ std::vector<std::string> Glob(std::string const &pattern, int flags)
    return result;
 }
                                                                        /*}}}*/
+
+std::string GetTempDir()
+{
+   const char *tmpdir = getenv("TMPDIR");
+
+#ifdef P_tmpdir
+   if (!tmpdir)
+      tmpdir = P_tmpdir;
+#endif
+
+   // check that tmpdir is set and exists
+   struct stat st;
+   if (!tmpdir || strlen(tmpdir) == 0 || stat(tmpdir, &st) != 0)
+      tmpdir = "/tmp";
+
+   return string(tmpdir);
+}