correct some style/performance/warnings from cppcheck
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 16 Jan 2014 21:19:49 +0000 (22:19 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Thu, 16 Jan 2014 21:19:49 +0000 (22:19 +0100)
The most "visible" change is from utime to utimensat/futimens
as the first one isn't part of POSIX anymore.

Reported-By: cppcheck
Git-Dch: Ignore

22 files changed:
apt-inst/dirstream.cc
apt-pkg/contrib/fileutl.cc
apt-pkg/contrib/gpgv.cc
apt-pkg/contrib/hashes.cc
apt-pkg/contrib/hashsum.cc
apt-pkg/deb/dpkgpm.cc
apt-pkg/install-progress.cc
apt-private/private-list.cc
apt-private/private-search.cc
ftparchive/multicompress.cc
methods/connect.cc
methods/copy.cc
methods/ftp.cc
methods/gzip.cc
methods/http.cc
methods/https.cc
methods/https.h
methods/mirror.cc
methods/rsh.cc
methods/server.cc
methods/server.h
test/interactive-helper/rpmver.cc

index 65d1aa1..b62bdca 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <errno.h>
-#include <utime.h>
 #include <unistd.h>
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -93,19 +92,18 @@ bool pkgDirStream::FinishedFile(Item &Itm,int Fd)
 {
    if (Fd < 0)
       return true;
-   
-   if (close(Fd) != 0)
-      return _error->Errno("close",_("Failed to close file %s"),Itm.Name);
 
    /* Set the modification times. The only way it can fail is if someone
       has futzed with our file, which is intolerable :> */
-   struct utimbuf Time;
-   Time.actime = Itm.MTime;
-   Time.modtime = Itm.MTime;
-   if (utime(Itm.Name,&Time) != 0)
-      _error->Errno("utime",_("Failed to close file %s"),Itm.Name);
-   
-   return true;   
+   struct timespec times[2];
+   times[0].tv_sec = times[1].tv_sec = Itm.MTime;
+   times[0].tv_nsec = times[1].tv_nsec = 0;
+   if (futimens(Fd, times) != 0)
+      _error->Errno("futimens", "Failed to set modification time for %s",Itm.Name);
+
+   if (close(Fd) != 0)
+      return _error->Errno("close",_("Failed to close file %s"),Itm.Name);
+   return true;
 }
                                                                        /*}}}*/
 // DirStream::Fail - Failed processing a file                          /*{{{*/
index efbf7aa..1c8acd5 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()), '/');
index 0a469dd..9de2270 100644 (file)
@@ -260,8 +260,7 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
 
    char *buf = NULL;
    size_t buf_size = 0;
-   ssize_t line_len = 0;
-   while ((line_len = getline(&buf, &buf_size, in)) != -1)
+   while (getline(&buf, &buf_size, in) != -1)
    {
       _strrstrip(buf);
       if (found_message_start == false)
@@ -355,7 +354,7 @@ bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &Me
       return _error->Error("Couldn't open temporary file to work with %s", ClearSignedFileName.c_str());
 
    _error->PushToStack();
-   bool const splitDone = SplitClearSignedFile(ClearSignedFileName.c_str(), &MessageFile, NULL, NULL);
+   bool const splitDone = SplitClearSignedFile(ClearSignedFileName, &MessageFile, NULL, NULL);
    bool const errorDone = _error->PendingError();
    _error->MergeWithStack();
    if (splitDone == false)
index b4c768d..890573d 100644 (file)
@@ -129,13 +129,12 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size, bool const addMD5,
                   bool const addSHA1, bool const addSHA256, bool const addSHA512)
 {
    unsigned char Buf[64*64];
-   ssize_t Res = 0;
-   int ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    {
       unsigned long long n = sizeof(Buf);
       if (!ToEOF) n = std::min(Size, n);
-      Res = read(Fd,Buf,n);
+      ssize_t const Res = read(Fd,Buf,n);
       if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
         return false;
       if (ToEOF && Res == 0) // EOF
index 289e43a..d021777 100644 (file)
@@ -9,13 +9,12 @@
 /* */
 bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
    unsigned char Buf[64 * 64];
-   ssize_t Res = 0;
-   int ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    {
       unsigned long long n = sizeof(Buf);
       if (!ToEOF) n = std::min(Size, n);
-      Res = read(Fd, Buf, n);
+      ssize_t const Res = read(Fd, Buf, n);
       if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
         return false;
       if (ToEOF && Res == 0) // EOF
@@ -27,7 +26,7 @@ bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
 }
 bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) {
    unsigned char Buf[64 * 64];
-   bool ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    {
       unsigned long long n = sizeof(Buf);
index 14ce133..1967d5d 100644 (file)
@@ -568,7 +568,6 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
    std::string prefix = APT::String::Strip(list[0]);
    std::string pkgname;
    std::string action;
-   ostringstream status;
 
    // "processing" has the form "processing: action: pkg or trigger"
    // with action = ["install", "configure", "remove", "purge", "disappear",
@@ -1652,7 +1651,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    io_errors.push_back(string("failed in write on buffer copy for %s"));
    io_errors.push_back(string("short read on buffer copy for %s"));
 
-   for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); I++)
+   for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); ++I)
    {
       vector<string> list = VectorizeString(dgettext("dpkg", (*I).c_str()), '%');
       if (list.size() > 1) {
@@ -1767,13 +1766,11 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    string histfile_name = _config->FindFile("Dir::Log::History");
    if (!histfile_name.empty())
    {
-      FILE *log = NULL;
-      char buf[1024];
-
       fprintf(report, "DpkgHistoryLog:\n");
-      log = fopen(histfile_name.c_str(),"r");
+      FILE* log = fopen(histfile_name.c_str(),"r");
       if(log != NULL)
       {
+        char buf[1024];
         while( fgets(buf, sizeof(buf), log) != NULL)
            fprintf(report, " %s", buf);
         fclose(log);
index fe065da..a3a4cc0 100644 (file)
@@ -242,7 +242,7 @@ PackageManagerFancy::~PackageManagerFancy()
 void PackageManagerFancy::staticSIGWINCH(int signum)
 {
    std::vector<PackageManagerFancy *>::const_iterator I;
-   for(I = instances.begin(); I != instances.end(); I++)
+   for(I = instances.begin(); I != instances.end(); ++I)
       (*I)->HandleSIGWINCH(signum);
 }
 
index a02ebf0..898ee72 100644 (file)
@@ -61,7 +61,7 @@ class PackageNameMatcher : public Matcher                             /*{{{*/
   public:
    PackageNameMatcher(const char **patterns)
    {
-      for(int i=0; patterns[i] != NULL; i++)
+      for(int i=0; patterns[i] != NULL; ++i)
       {
          std::string pattern = patterns[i];
 #ifdef PACKAGE_MATCHER_ABI_COMPAT
@@ -79,12 +79,12 @@ class PackageNameMatcher : public Matcher                           /*{{{*/
    }
    virtual ~PackageNameMatcher()
    {
-      for(J=filters.begin(); J != filters.end(); J++)
+      for(J=filters.begin(); J != filters.end(); ++J)
          delete *J;
    }
    virtual bool operator () (const pkgCache::PkgIterator &P) 
    {
-      for(J=filters.begin(); J != filters.end(); J++)
+      for(J=filters.begin(); J != filters.end(); ++J)
       {
          APT::CacheFilter::PackageMatcher *cachefilter = *J;
          if((*cachefilter)(P)) 
@@ -104,7 +104,7 @@ void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,  /*{{{*/
                      std::ostream &outs)
 {
    for (pkgCache::VerIterator Ver = P.VersionList();
-        Ver.end() == false; Ver++
+        Ver.end() == false; ++Ver
       ListSingleVersion(CacheFile, records, Ver, outs);
 }
                                                                        /*}}}*/
@@ -142,7 +142,7 @@ bool List(CommandLine &Cmd)
                             Cache->Head().PackageCount,
                             _("Listing"));
    GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress);
-   for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); V++)
+   for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V)
    {
       std::stringstream outs;
       if(_config->FindB("APT::Cmd::All-Versions", false) == true)
@@ -159,7 +159,7 @@ bool List(CommandLine &Cmd)
 
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // output the sorted map
-   for (K = output_map.begin(); K != output_map.end(); K++)
+   for (K = output_map.begin(); K != output_map.end(); ++K)
       std::cout << (*K).second << std::endl;
 
 
index ff4140f..ade1235 100644 (file)
@@ -61,18 +61,18 @@ bool FullTextSearch(CommandLine &CmdL)                                      /*{{{*/
    progress.OverallProgress(50, 100, 50,  _("Full Text Search"));
    progress.SubProgress(bag.size());
    int Done = 0;
-   for ( ;V != bag.end(); V++)
+   for ( ;V != bag.end(); ++V)
    {
       if (Done%500 == 0)
          progress.Progress(Done);
-      Done++;
+      ++Done;
       
       int i;
       pkgCache::DescIterator Desc = V.TranslatedDescription();
       pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
      
       bool all_found = true;
-      for(i=0; patterns[i] != NULL; i++) 
+      for(i=0; patterns[i] != NULL; ++i)
       {
          // FIXME: use regexp instead of simple find()
          const char *pattern = patterns[i];
@@ -93,7 +93,7 @@ bool FullTextSearch(CommandLine &CmdL)                                        /*{{{*/
 
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // output the sorted map
-   for (K = output_map.begin(); K != output_map.end(); K++)
+   for (K = output_map.begin(); K != output_map.end(); ++K)
       std::cout << (*K).second << std::endl;
 
    return true;
index 1fea589..265fb1a 100644 (file)
@@ -21,9 +21,9 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/md5.h>
 
+#include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <utime.h>
 #include <unistd.h>
 #include <iostream>
 
@@ -234,14 +234,12 @@ bool MultiCompress::Finalize(unsigned long long &OutSize)
       else
       {
         // Update the mtime if necessary
-        if (UpdateMTime > 0 && 
+        if (UpdateMTime > 0 &&
             (Now - St.st_mtime > (signed)UpdateMTime || St.st_mtime > Now))
         {
-           struct utimbuf Buf;
-           Buf.actime = Buf.modtime = Now;
-           utime(I->Output.c_str(),&Buf);
+           utimensat(AT_FDCWD, I->Output.c_str(), NULL, AT_SYMLINK_NOFOLLOW);
            Changed = true;
-        }           
+        }
       }
       
       // Force the file permissions
index fc7a72e..d9c9a1d 100644 (file)
@@ -142,9 +142,9 @@ bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
    // Convert the port name/number
    char ServStr[300];
    if (Port != 0)
-      snprintf(ServStr,sizeof(ServStr),"%u",Port);
+      snprintf(ServStr,sizeof(ServStr),"%i", Port);
    else
-      snprintf(ServStr,sizeof(ServStr),"%s",Service);
+      snprintf(ServStr,sizeof(ServStr),"%s", Service);
    
    /* We used a cached address record.. Yes this is against the spec but
       the way we have setup our rotating dns suggests that this is more
@@ -190,7 +190,7 @@ bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
            {
               if (DefPort != 0)
               {
-                 snprintf(ServStr,sizeof(ServStr),"%u",DefPort);
+                 snprintf(ServStr, sizeof(ServStr), "%i", DefPort);
                  DefPort = 0;
                  continue;
               }
index e81d002..744cc2b 100644 (file)
@@ -18,7 +18,6 @@
 #include <apt-pkg/hashes.h>
 
 #include <sys/stat.h>
-#include <utime.h>
 #include <unistd.h>
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -71,18 +70,19 @@ bool CopyMethod::Fetch(FetchItem *Itm)
    }
 
    From.Close();
-   To.Close();
-   
+
    // Transfer the modification times
-   struct utimbuf TimeBuf;
-   TimeBuf.actime = Buf.st_atime;
-   TimeBuf.modtime = Buf.st_mtime;
-   if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0)
+   struct timespec times[2];
+   times[0].tv_sec = Buf.st_atime;
+   times[1].tv_sec = Buf.st_mtime;
+   times[0].tv_nsec = times[1].tv_nsec = 0;
+   if (futimens(To.Fd(), times) != 0)
    {
       To.OpFail();
-      return _error->Errno("utime",_("Failed to set modification time"));
+      return _error->Errno("futimens",_("Failed to set modification time"));
    }
-   
+   To.Close();
+
    Hashes Hash;
    FileFd Fd(Res.Filename, FileFd::ReadOnly);
    Hash.AddFD(Fd);
index 979adca..2d05364 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -953,14 +952,16 @@ void FtpMethod::SigTerm(int)
 {
    if (FailFd == -1)
       _exit(100);
-   close(FailFd);
-   
+
    // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(FailFile.c_str(),&UBuf);
-   
+   struct timespec times[2];
+   times[0].tv_sec = FailTime;
+   times[1].tv_sec = FailTime;
+   times[0].tv_nsec = times[1].tv_nsec = 0;
+   futimens(FailFd, times);
+
+   close(FailFd);
+
    _exit(100);
 }
                                                                        /*}}}*/
@@ -1059,13 +1060,14 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing) == false)
       {
         Fd.Close();
-        
+
         // Timestamp
-        struct utimbuf UBuf;
-        UBuf.actime = FailTime;
-        UBuf.modtime = FailTime;
-        utime(FailFile.c_str(),&UBuf);
-        
+        struct timespec times[2];
+        times[0].tv_sec = FailTime;
+        times[1].tv_sec = FailTime;
+        times[0].tv_nsec = times[1].tv_nsec = 0;
+        futimens(FailFd, times);
+
         // If the file is missing we hard fail and delete the destfile
         // otherwise transient fail
         if (Missing == true) {
@@ -1077,20 +1079,21 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       }
 
       Res.Size = Fd.Size();
+
+      // Timestamp
+      struct timespec times[2];
+      times[0].tv_sec = FailTime;
+      times[1].tv_sec = FailTime;
+      times[0].tv_nsec = times[1].tv_nsec = 0;
+      futimens(Fd.Fd(), times);
+      FailFd = -1;
    }
-   
+
    Res.LastModified = FailTime;
    Res.TakeHashes(Hash);
-   
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(Queue->DestFile.c_str(),&UBuf);
-   FailFd = -1;
 
    URIDone(Res);
-   
+
    return true;
 }
                                                                        /*}}}*/
index 48c8e98..f1edb35 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <sys/stat.h>
 #include <unistd.h>
-#include <utime.h>
 #include <stdio.h>
 #include <errno.h>
 #include <apti18n.h>
@@ -94,32 +93,35 @@ bool GzipMethod::Fetch(FetchItem *Itm)
    }
    
    From.Close();
-   To.Close();
-   
+
    if (Failed == true)
       return false;
-   
+
    // Transfer the modification times
    struct stat Buf;
    if (stat(Path.c_str(),&Buf) != 0)
       return _error->Errno("stat",_("Failed to stat"));
 
-   struct utimbuf TimeBuf;
-   TimeBuf.actime = Buf.st_atime;
-   TimeBuf.modtime = Buf.st_mtime;
-   if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0)
-      return _error->Errno("utime",_("Failed to set modification time"));
+   struct timespec times[2];
+   times[0].tv_sec = Buf.st_atime;
+   times[1].tv_sec = Buf.st_mtime;
+   times[0].tv_nsec = times[1].tv_nsec = 0;
+   if (futimens(To.Fd(), times) != 0)
+   {
+      To.OpFail();
+      return _error->Errno("futimens",_("Failed to set modification time"));
+   }
+   Res.Size = To.FileSize();
+   To.Close();
 
    if (stat(Itm->DestFile.c_str(),&Buf) != 0)
       return _error->Errno("stat",_("Failed to stat"));
-   
+
    // Return a Done response
    Res.LastModified = Buf.st_mtime;
-   Res.Size = Buf.st_size;
    Res.TakeHashes(Hash);
 
    URIDone(Res);
-   
    return true;
 }
                                                                        /*}}}*/
index b22b61e..e1390af 100644 (file)
@@ -97,8 +97,6 @@ void CircleBuf::Reset()
    is non-blocking.. */
 bool CircleBuf::Read(int Fd)
 {
-   unsigned long long BwReadMax;
-
    while (1)
    {
       // Woops, buffer is full
@@ -106,7 +104,7 @@ bool CircleBuf::Read(int Fd)
         return true;
 
       // what's left to read in this tick
-      BwReadMax = CircleBuf::BwReadLimit/BW_HZ;
+      unsigned long long const BwReadMax = CircleBuf::BwReadLimit/BW_HZ;
 
       if(CircleBuf::BwReadLimit) {
         struct timeval now;
index 2a56243..e16e363 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -405,10 +404,11 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
    curl_easy_getinfo(curl, CURLINFO_FILETIME, &Res.LastModified);
    if (Res.LastModified != -1)
    {
-      struct utimbuf UBuf;
-      UBuf.actime = Res.LastModified;
-      UBuf.modtime = Res.LastModified;
-      utime(File->Name().c_str(),&UBuf);
+      struct timespec times[2];
+      times[0].tv_sec = Res.LastModified;
+      times[1].tv_sec = Res.LastModified;
+      times[0].tv_nsec = times[1].tv_nsec = 0;
+      futimens(File->Fd(), times);
    }
    else
       Res.LastModified = resultStat.st_mtime;
index 8632d6d..89a89d1 100644 (file)
@@ -65,7 +65,7 @@ class HttpsMethod : public pkgAcqMethod
    public:
    FileFd *File;
       
-   HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig) 
+   HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), File(NULL)
    {
       File = 0;
       curl = curl_easy_init();
index 8543663..83ef0d1 100644 (file)
@@ -114,7 +114,7 @@ bool MirrorMethod::Clean(string Dir)
       for(I=list.begin(); I != list.end(); ++I)
       {
         string uri = (*I)->GetURI();
-        if(uri.find("mirror://") != 0)
+        if(uri.compare(0, strlen("mirror://"), "mirror://") != 0)
            continue;
         string BaseUri = uri.substr(0,uri.size()-1);
         if (URItoFileName(BaseUri) == Dir->d_name)
@@ -198,9 +198,9 @@ bool MirrorMethod::RandomizeMirrorFile(string mirror_file)
    // "stable" on the same machine. this is to avoid running into out-of-sync
    // issues (i.e. Release/Release.gpg different on each mirror)
    struct utsname buf;
-   int seed=1, i;
+   int seed=1;
    if(uname(&buf) == 0) {
-      for(i=0,seed=1; buf.nodename[i] != 0; i++) {
+      for(int i=0,seed=1; buf.nodename[i] != 0; ++i) {
          seed = seed * 31 + buf.nodename[i];
       }
    }
@@ -306,7 +306,7 @@ bool MirrorMethod::InitMirrors()
       if (s.size() == 0)
          continue;
       // ignore non http lines
-      if (s.find("http://") != 0)
+      if (s.compare(0, strlen("http://"), "http://") != 0)
          continue;
 
       AllMirrors.push_back(s);
index d76dca6..a441220 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -395,13 +394,14 @@ void RSHMethod::SigTerm(int sig)
 {
    if (FailFd == -1)
       _exit(100);
-   close(FailFd);
 
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(FailFile.c_str(),&UBuf);
+   // Transfer the modification times
+   struct timespec times[2];
+   times[0].tv_sec = FailTime;
+   times[1].tv_sec = FailTime;
+   times[0].tv_nsec = times[1].tv_nsec = 0;
+   futimens(FailFd, times);
+   close(FailFd);
 
    _exit(100);
 }
@@ -488,10 +488,11 @@ bool RSHMethod::Fetch(FetchItem *Itm)
         Fd.Close();
 
         // Timestamp
-        struct utimbuf UBuf;
-        UBuf.actime = FailTime;
-        UBuf.modtime = FailTime;
-        utime(FailFile.c_str(),&UBuf);
+        struct timespec times[2];
+        times[0].tv_sec = FailTime;
+        times[1].tv_sec = FailTime;
+        times[0].tv_nsec = times[1].tv_nsec = 0;
+        futimens(FailFd, times);
 
         // If the file is missing we hard fail otherwise transient fail
         if (Missing == true)
@@ -501,18 +502,17 @@ bool RSHMethod::Fetch(FetchItem *Itm)
       }
 
       Res.Size = Fd.Size();
+      struct timespec times[2];
+      times[0].tv_sec = FailTime;
+      times[1].tv_sec = FailTime;
+      times[0].tv_nsec = times[1].tv_nsec = 0;
+      futimens(Fd.Fd(), times);
+      FailFd = -1;
    }
 
    Res.LastModified = FailTime;
    Res.TakeHashes(Hash);
 
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(Queue->DestFile.c_str(),&UBuf);
-   FailFd = -1;
-
    URIDone(Res);
 
    return true;
index a212844..e12c23c 100644 (file)
@@ -17,9 +17,9 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/netrc.h>
 
+#include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -368,14 +368,14 @@ void ServerMethod::SigTerm(int)
 {
    if (FailFd == -1)
       _exit(100);
+
+   struct timespec times[2];
+   times[0].tv_sec = FailTime;
+   times[1].tv_sec = FailTime;
+   times[0].tv_nsec = times[1].tv_nsec = 0;
+   futimens(FailFd, times);
    close(FailFd);
-   
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(FailFile.c_str(),&UBuf);
-   
+
    _exit(100);
 }
                                                                        /*}}}*/
@@ -539,11 +539,10 @@ int ServerMethod::Loop()
            File = 0;
            
            // Timestamp
-           struct utimbuf UBuf;
-           time(&UBuf.actime);
-           UBuf.actime = Server->Date;
-           UBuf.modtime = Server->Date;
-           utime(Queue->DestFile.c_str(),&UBuf);
+           struct timespec times[2];
+           times[0].tv_sec = times[1].tv_sec = Server->Date;
+           times[0].tv_nsec = times[1].tv_nsec = 0;
+           utimensat(AT_FDCWD, Queue->DestFile.c_str(), times, AT_SYMLINK_NOFOLLOW);
 
            // Send status to APT
            if (Result == true)
index 4dc6a1f..2b81e61 100644 (file)
@@ -137,7 +137,7 @@ class ServerMethod : public pkgAcqMethod
    virtual ServerState * CreateServerState(URI uri) = 0;
    virtual void RotateDNS() = 0;
 
-   ServerMethod(const char *Ver,unsigned long Flags = 0) : pkgAcqMethod(Ver, Flags), PipelineDepth(0), AllowRedirect(false), Debug(false) {};
+   ServerMethod(const char *Ver,unsigned long Flags = 0) : pkgAcqMethod(Ver, Flags), Server(NULL), File(NULL), PipelineDepth(0), AllowRedirect(false), Debug(false) {};
    virtual ~ServerMethod() {};
 };
 
index 9fc807d..15c96cb 100644 (file)
@@ -2,6 +2,7 @@
 #include <rpm/rpmio.h>
 #include <rpm/misc.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <ctype.h>
 
 #define xisdigit(x) isdigit(x)
@@ -12,10 +13,8 @@ using namespace std;
 
 int rpmvercmp(const char * a, const char * b)
 {
-    char oldch1, oldch2;
     char * str1, * str2;
     char * one, * two;
-    int rc;
     int isnum;
 
     /* easy comparison to see if versions are identical */
@@ -53,9 +52,9 @@ int rpmvercmp(const char * a, const char * b)
 
        /* save character at the end of the alpha or numeric segment */
        /* so that they can be restored after the comparison */
-       oldch1 = *str1;
+       char oldch1 = *str1;
        *str1 = '\0';
-       oldch2 = *str2;
+       char oldch2 = *str2;
        *str2 = '\0';
 
        /* take care of the case where the two version segments are */
@@ -81,7 +80,7 @@ int rpmvercmp(const char * a, const char * b)
        /* segments are alpha or if they are numeric.  don't return  */
        /* if they are equal because there might be more segments to */
        /* compare */
-       rc = strcmp(one, two);
+       int rc = strcmp(one, two);
        if (rc) return rc;
 
        /* restore character that was replaced by null above */