]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
CDROM method
[apt.git] / apt-pkg / contrib / fileutl.cc
index 3d5c4686b0d2ac4b28d9375389ceb478dffaa589..379641c2c72d7bfa627908a710370f602821ffd0 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: fileutl.cc,v 1.11 1998/10/22 04:56:47 jgg Exp $
+// $Id: fileutl.cc,v 1.16 1998/11/27 04:20:52 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -29,7 +29,7 @@
 // CopyFile - Buffered copy of a file                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expected to set things so that failure causes erasure */
-bool CopyFile(FileFd From,FileFd To)
+bool CopyFile(FileFd &From,FileFd &To)
 {
    if (From.IsOpen() == false || To.IsOpen() == false)
       return false;
@@ -119,6 +119,18 @@ string flNotDir(string File)
    return string(File,Res,Res - File.length());
 }
                                                                        /*}}}*/
+// flNotFile - Strip the file from the directory name                  /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string flNotFile(string File)
+{
+   string::size_type Res = File.rfind('/');
+   if (Res == string::npos)
+      return File;
+   Res++;
+   return string(File,0,Res);
+}
+                                                                       /*}}}*/
 // SetCloseExec - Set the close on exec flag                           /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -174,9 +186,13 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms)
       break;
       
       case WriteEmpty:
-      unlink(FileName.c_str());
-      iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_EXCL,Perms);
-      break;
+      {
+        struct stat Buf;
+        if (stat(FileName.c_str(),&Buf) == 0 && S_ISLNK(Buf.st_mode))
+           unlink(FileName.c_str());
+        iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms);
+        break;
+      }
       
       case WriteExists:
       iFd = open(FileName.c_str(),O_RDWR);
@@ -184,19 +200,16 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms)
 
       case WriteAny:
       iFd = open(FileName.c_str(),O_RDWR | O_CREAT,Perms);
-      break;
-      
-      // Dont use this in public directories
-      case LockEmpty:
-      iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms);
-      break;
+      break;      
    }  
 
    if (iFd < 0)
       _error->Errno("open","Could not open file %s",FileName.c_str());
    else
+   {
       this->FileName = FileName;
-   SetCloseExec(iFd,true);
+      SetCloseExec(iFd,true);
+   }   
 }
                                                                        /*}}}*/
 // FileFd::~File - Closes the file                                     /*{{{*/
@@ -225,7 +238,7 @@ bool FileFd::Read(void *To,unsigned long Size)
 // FileFd::Write - Write to the file                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool FileFd::Write(void *From,unsigned long Size)
+bool FileFd::Write(const void *From,unsigned long Size)
 {
    if (write(iFd,From,Size) != (signed)Size)
    {