]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
tests: try to support spaces in TMPDIR
[apt.git] / apt-pkg / contrib / fileutl.cc
index 837edef4b1e015a075549c5cccbc672c7c3149c3..02b27f5cfd2e05a463b9f93518fcc3698d433b8e 100644 (file)
@@ -158,24 +158,18 @@ bool CopyFile(FileFd &From,FileFd &To)
    if (From.IsOpen() == false || To.IsOpen() == false ||
         From.Failed() == true || To.Failed() == true)
       return false;
-   
+
    // Buffered copy between fds
    std::unique_ptr<unsigned char[]> Buf(new unsigned char[64000]);
-   unsigned long long Size = From.Size();
-   while (Size != 0)
-   {
-      unsigned long long ToRead = Size;
-      if (Size > 64000)
-        ToRead = 64000;
-      
-      if (From.Read(Buf.get(),ToRead) == false ||
+   constexpr unsigned long long BufSize = sizeof(Buf.get())/sizeof(Buf.get()[0]);
+   unsigned long long ToRead = 0;
+   do {
+      if (From.Read(Buf.get(),BufSize, &ToRead) == false ||
          To.Write(Buf.get(),ToRead) == false)
         return false;
-      
-      Size -= ToRead;
-   }
+   } while (ToRead != 0);
 
-   return true;   
+   return true;
 }
                                                                        /*}}}*/
 // GetLock - Gets a lock file                                          /*{{{*/
@@ -671,7 +665,7 @@ string flAbsPath(string File)
    char *p = realpath(File.c_str(), NULL);
    if (p == NULL)
    {
-      _error->Errno("realpath", "flAbsPath failed");
+      _error->Errno("realpath", "flAbsPath on %s failed", File.c_str());
       return "";
    }
    std::string AbsPath(p);
@@ -2236,11 +2230,14 @@ bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode)/
    {
       close(Pipe[1]);
       fd = Pipe[0];
-   } else if(Mode == FileFd::WriteOnly)
+   }
+   else if(Mode == FileFd::WriteOnly)
    {
       close(Pipe[0]);
       fd = Pipe[1];
    }
+   else
+      return _error->Error("Popen supports ReadOnly (x)or WriteOnly mode only");
    Fd.OpenDescriptor(fd, Mode, FileFd::None, true);
 
    return true;