X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b2e465d6d32d2dc884f58b94acb7e35f671a87fe..7da2b37588408ab538e16f2d93ffb47a19e7a090:/apt-pkg/contrib/fileutl.cc?ds=sidebyside diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 0907f4dcd..4ba8ab05a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: fileutl.cc,v 1.35 2001/02/20 07:03:17 jgg Exp $ +// $Id: fileutl.cc,v 1.42 2002/09/14 05:29:22 jgg Exp $ /* ###################################################################### File Utilities @@ -9,7 +9,7 @@ GetLock - dpkg compatible lock file manipulation (fcntl) This source is placed in the Public Domain, do with it what you will - It was originally written by Jason Gunthorpe. + It was originally written by Jason Gunthorpe . ##################################################################### */ /*}}}*/ @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -33,6 +34,8 @@ #include /*}}}*/ +using namespace std; + // CopyFile - Buffered copy of a file /*{{{*/ // --------------------------------------------------------------------- /* The caller is expected to set things so that failure causes erasure */ @@ -153,12 +156,12 @@ string flNotDir(string File) /*}}}*/ // flNotFile - Strip the file from the directory name /*{{{*/ // --------------------------------------------------------------------- -/* */ +/* Result ends in a / */ string flNotFile(string File) { string::size_type Res = File.rfind('/'); if (Res == string::npos) - return File; + return "./"; Res++; return string(File,0,Res); } @@ -334,7 +337,7 @@ int ExecFork() /*}}}*/ // ExecWait - Fancy waitpid /*{{{*/ // --------------------------------------------------------------------- -/* Waits for the given sub process. If Reap is set the no errors are +/* Waits for the given sub process. If Reap is set then no errors are generated. Otherwise a failed subprocess will generate a proper descriptive message */ bool ExecWait(int Pid,const char *Name,bool Reap) @@ -403,6 +406,11 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) case WriteAny: iFd = open(FileName.c_str(),O_RDWR | O_CREAT,Perms); break; + + case WriteTemp: + unlink(FileName.c_str()); + iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_EXCL,Perms); + break; } if (iFd < 0) @@ -426,10 +434,13 @@ FileFd::~FileFd() // --------------------------------------------------------------------- /* We are carefull to handle interruption by a signal while reading gracefully. */ -bool FileFd::Read(void *To,unsigned long Size,bool AllowEof) +bool FileFd::Read(void *To,unsigned long Size,unsigned long *Actual) { int Res; errno = 0; + if (Actual != 0) + *Actual = 0; + do { Res = read(iFd,To,Size); @@ -443,6 +454,8 @@ bool FileFd::Read(void *To,unsigned long Size,bool AllowEof) To = (char *)To + Res; Size -= Res; + if (Actual != 0) + *Actual += Res; } while (Res > 0 && Size > 0); @@ -450,7 +463,7 @@ bool FileFd::Read(void *To,unsigned long Size,bool AllowEof) return true; // Eof handling - if (AllowEof == true) + if (Actual != 0) { Flags |= HitEof; return true;