Browse Source

correct some style/performance/warnings from cppcheck

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
David Kalnischkies 12 years ago
parent
commit
9ce3cfc930

+ 9 - 11
apt-inst/dirstream.cc

@@ -20,7 +20,6 @@
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <errno.h>
 #include <errno.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <apti18n.h>
 #include <apti18n.h>
 									/*}}}*/
 									/*}}}*/
@@ -93,19 +92,18 @@ bool pkgDirStream::FinishedFile(Item &Itm,int Fd)
 {
 {
    if (Fd < 0)
    if (Fd < 0)
       return true;
       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
    /* Set the modification times. The only way it can fail is if someone
       has futzed with our file, which is intolerable :> */
       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				/*{{{*/
 // DirStream::Fail - Failed processing a file				/*{{{*/

+ 1 - 1
apt-pkg/contrib/fileutl.cc

@@ -319,7 +319,7 @@ bool CreateDirectory(string const &Parent, string const &Path)
       return false;
       return false;
 
 
    // we are not going to create directories "into the blue"
    // 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;
       return false;
 
 
    vector<string> const dirs = VectorizeString(Path.substr(Parent.size()), '/');
    vector<string> const dirs = VectorizeString(Path.substr(Parent.size()), '/');

+ 2 - 3
apt-pkg/contrib/gpgv.cc

@@ -260,8 +260,7 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
 
 
    char *buf = NULL;
    char *buf = NULL;
    size_t buf_size = 0;
    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);
       _strrstrip(buf);
       if (found_message_start == false)
       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());
       return _error->Error("Couldn't open temporary file to work with %s", ClearSignedFileName.c_str());
 
 
    _error->PushToStack();
    _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();
    bool const errorDone = _error->PendingError();
    _error->MergeWithStack();
    _error->MergeWithStack();
    if (splitDone == false)
    if (splitDone == false)

+ 2 - 3
apt-pkg/contrib/hashes.cc

@@ -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)
 		   bool const addSHA1, bool const addSHA256, bool const addSHA512)
 {
 {
    unsigned char Buf[64*64];
    unsigned char Buf[64*64];
-   ssize_t Res = 0;
-   int ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    while (Size != 0 || ToEOF)
    {
    {
       unsigned long long n = sizeof(Buf);
       unsigned long long n = sizeof(Buf);
       if (!ToEOF) n = std::min(Size, n);
       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
       if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
 	 return false;
 	 return false;
       if (ToEOF && Res == 0) // EOF
       if (ToEOF && Res == 0) // EOF

+ 3 - 4
apt-pkg/contrib/hashsum.cc

@@ -9,13 +9,12 @@
 /* */
 /* */
 bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
 bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
    unsigned char Buf[64 * 64];
    unsigned char Buf[64 * 64];
-   ssize_t Res = 0;
-   int ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    while (Size != 0 || ToEOF)
    {
    {
       unsigned long long n = sizeof(Buf);
       unsigned long long n = sizeof(Buf);
       if (!ToEOF) n = std::min(Size, n);
       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
       if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
 	 return false;
 	 return false;
       if (ToEOF && Res == 0) // EOF
       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) {
 bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) {
    unsigned char Buf[64 * 64];
    unsigned char Buf[64 * 64];
-   bool ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    while (Size != 0 || ToEOF)
    {
    {
       unsigned long long n = sizeof(Buf);
       unsigned long long n = sizeof(Buf);

+ 3 - 6
apt-pkg/deb/dpkgpm.cc

@@ -568,7 +568,6 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
    std::string prefix = APT::String::Strip(list[0]);
    std::string prefix = APT::String::Strip(list[0]);
    std::string pkgname;
    std::string pkgname;
    std::string action;
    std::string action;
-   ostringstream status;
 
 
    // "processing" has the form "processing: action: pkg or trigger"
    // "processing" has the form "processing: action: pkg or trigger"
    // with action = ["install", "configure", "remove", "purge", "disappear",
    // 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("failed in write on buffer copy for %s"));
    io_errors.push_back(string("short read 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()), '%');
       vector<string> list = VectorizeString(dgettext("dpkg", (*I).c_str()), '%');
       if (list.size() > 1) {
       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");
    string histfile_name = _config->FindFile("Dir::Log::History");
    if (!histfile_name.empty())
    if (!histfile_name.empty())
    {
    {
-      FILE *log = NULL;
-      char buf[1024];
-
       fprintf(report, "DpkgHistoryLog:\n");
       fprintf(report, "DpkgHistoryLog:\n");
-      log = fopen(histfile_name.c_str(),"r");
+      FILE* log = fopen(histfile_name.c_str(),"r");
       if(log != NULL)
       if(log != NULL)
       {
       {
+	 char buf[1024];
 	 while( fgets(buf, sizeof(buf), log) != NULL)
 	 while( fgets(buf, sizeof(buf), log) != NULL)
 	    fprintf(report, " %s", buf);
 	    fprintf(report, " %s", buf);
 	 fclose(log);
 	 fclose(log);

+ 1 - 1
apt-pkg/install-progress.cc

@@ -242,7 +242,7 @@ PackageManagerFancy::~PackageManagerFancy()
 void PackageManagerFancy::staticSIGWINCH(int signum)
 void PackageManagerFancy::staticSIGWINCH(int signum)
 {
 {
    std::vector<PackageManagerFancy *>::const_iterator I;
    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);
       (*I)->HandleSIGWINCH(signum);
 }
 }
 
 

+ 6 - 6
apt-private/private-list.cc

@@ -61,7 +61,7 @@ class PackageNameMatcher : public Matcher				/*{{{*/
   public:
   public:
    PackageNameMatcher(const char **patterns)
    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];
          std::string pattern = patterns[i];
 #ifdef PACKAGE_MATCHER_ABI_COMPAT
 #ifdef PACKAGE_MATCHER_ABI_COMPAT
@@ -79,12 +79,12 @@ class PackageNameMatcher : public Matcher				/*{{{*/
    }
    }
    virtual ~PackageNameMatcher()
    virtual ~PackageNameMatcher()
    {
    {
-      for(J=filters.begin(); J != filters.end(); J++)
+      for(J=filters.begin(); J != filters.end(); ++J)
          delete *J;
          delete *J;
    }
    }
    virtual bool operator () (const pkgCache::PkgIterator &P) 
    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;
          APT::CacheFilter::PackageMatcher *cachefilter = *J;
          if((*cachefilter)(P)) 
          if((*cachefilter)(P)) 
@@ -104,7 +104,7 @@ void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,	/*{{{*/
                      std::ostream &outs)
                      std::ostream &outs)
 {
 {
    for (pkgCache::VerIterator Ver = P.VersionList();
    for (pkgCache::VerIterator Ver = P.VersionList();
-        Ver.end() == false; Ver++) 
+        Ver.end() == false; ++Ver) 
       ListSingleVersion(CacheFile, records, Ver, outs);
       ListSingleVersion(CacheFile, records, Ver, outs);
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -142,7 +142,7 @@ bool List(CommandLine &Cmd)
                             Cache->Head().PackageCount,
                             Cache->Head().PackageCount,
                             _("Listing"));
                             _("Listing"));
    GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress);
    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;
       std::stringstream outs;
       if(_config->FindB("APT::Cmd::All-Versions", false) == true)
       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)
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // output the sorted map
    // 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;
       std::cout << (*K).second << std::endl;
 
 
 
 

+ 4 - 4
apt-private/private-search.cc

@@ -61,18 +61,18 @@ bool FullTextSearch(CommandLine &CmdL)					/*{{{*/
    progress.OverallProgress(50, 100, 50,  _("Full Text Search"));
    progress.OverallProgress(50, 100, 50,  _("Full Text Search"));
    progress.SubProgress(bag.size());
    progress.SubProgress(bag.size());
    int Done = 0;
    int Done = 0;
-   for ( ;V != bag.end(); V++)
+   for ( ;V != bag.end(); ++V)
    {
    {
       if (Done%500 == 0)
       if (Done%500 == 0)
          progress.Progress(Done);
          progress.Progress(Done);
-      Done++;
+      ++Done;
       
       
       int i;
       int i;
       pkgCache::DescIterator Desc = V.TranslatedDescription();
       pkgCache::DescIterator Desc = V.TranslatedDescription();
       pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
       pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
      
      
       bool all_found = true;
       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()
          // FIXME: use regexp instead of simple find()
          const char *pattern = patterns[i];
          const char *pattern = patterns[i];
@@ -93,7 +93,7 @@ bool FullTextSearch(CommandLine &CmdL)					/*{{{*/
 
 
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
    // output the sorted map
    // 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;
       std::cout << (*K).second << std::endl;
 
 
    return true;
    return true;

+ 4 - 6
ftparchive/multicompress.cc

@@ -21,9 +21,9 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/md5.h>
 
 
+#include <fcntl.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <iostream>
 #include <iostream>
 
 
@@ -234,14 +234,12 @@ bool MultiCompress::Finalize(unsigned long long &OutSize)
       else
       else
       {
       {
 	 // Update the mtime if necessary
 	 // Update the mtime if necessary
-	 if (UpdateMTime > 0 && 
+	 if (UpdateMTime > 0 &&
 	     (Now - St.st_mtime > (signed)UpdateMTime || St.st_mtime > Now))
 	     (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;
 	    Changed = true;
-	 }	     
+	 }
       }
       }
       
       
       // Force the file permissions
       // Force the file permissions

+ 3 - 3
methods/connect.cc

@@ -142,9 +142,9 @@ bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
    // Convert the port name/number
    // Convert the port name/number
    char ServStr[300];
    char ServStr[300];
    if (Port != 0)
    if (Port != 0)
-      snprintf(ServStr,sizeof(ServStr),"%u",Port);
+      snprintf(ServStr,sizeof(ServStr),"%i", Port);
    else
    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
    /* 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
       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)
 	       if (DefPort != 0)
 	       {
 	       {
-		  snprintf(ServStr,sizeof(ServStr),"%u",DefPort);
+		  snprintf(ServStr, sizeof(ServStr), "%i", DefPort);
 		  DefPort = 0;
 		  DefPort = 0;
 		  continue;
 		  continue;
 	       }
 	       }

+ 9 - 9
methods/copy.cc

@@ -18,7 +18,6 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/hashes.h>
 
 
 #include <sys/stat.h>
 #include <sys/stat.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <apti18n.h>
 #include <apti18n.h>
 									/*}}}*/
 									/*}}}*/
@@ -71,18 +70,19 @@ bool CopyMethod::Fetch(FetchItem *Itm)
    }
    }
 
 
    From.Close();
    From.Close();
-   To.Close();
-   
+
    // Transfer the modification times
    // 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();
       To.OpFail();
-      return _error->Errno("utime",_("Failed to set modification time"));
+      return _error->Errno("futimens",_("Failed to set modification time"));
    }
    }
-   
+   To.Close();
+
    Hashes Hash;
    Hashes Hash;
    FileFd Fd(Res.Filename, FileFd::ReadOnly);
    FileFd Fd(Res.Filename, FileFd::ReadOnly);
    Hash.AddFD(Fd);
    Hash.AddFD(Fd);

+ 26 - 23
methods/ftp.cc

@@ -26,7 +26,6 @@
 
 
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -953,14 +952,16 @@ void FtpMethod::SigTerm(int)
 {
 {
    if (FailFd == -1)
    if (FailFd == -1)
       _exit(100);
       _exit(100);
-   close(FailFd);
-   
+
    // Timestamp
    // 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);
    _exit(100);
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -1059,13 +1060,14 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing) == false)
       if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing) == false)
       {
       {
 	 Fd.Close();
 	 Fd.Close();
-	 
+
 	 // Timestamp
 	 // 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
 	 // If the file is missing we hard fail and delete the destfile
 	 // otherwise transient fail
 	 // otherwise transient fail
 	 if (Missing == true) {
 	 if (Missing == true) {
@@ -1077,20 +1079,21 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       }
       }
 
 
       Res.Size = Fd.Size();
       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.LastModified = FailTime;
    Res.TakeHashes(Hash);
    Res.TakeHashes(Hash);
-   
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(Queue->DestFile.c_str(),&UBuf);
-   FailFd = -1;
 
 
    URIDone(Res);
    URIDone(Res);
-   
+
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 14 - 12
methods/gzip.cc

@@ -19,7 +19,6 @@
 
 
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <utime.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <errno.h>
 #include <errno.h>
 #include <apti18n.h>
 #include <apti18n.h>
@@ -94,32 +93,35 @@ bool GzipMethod::Fetch(FetchItem *Itm)
    }
    }
    
    
    From.Close();
    From.Close();
-   To.Close();
-   
+
    if (Failed == true)
    if (Failed == true)
       return false;
       return false;
-   
+
    // Transfer the modification times
    // Transfer the modification times
    struct stat Buf;
    struct stat Buf;
    if (stat(Path.c_str(),&Buf) != 0)
    if (stat(Path.c_str(),&Buf) != 0)
       return _error->Errno("stat",_("Failed to stat"));
       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)
    if (stat(Itm->DestFile.c_str(),&Buf) != 0)
       return _error->Errno("stat",_("Failed to stat"));
       return _error->Errno("stat",_("Failed to stat"));
-   
+
    // Return a Done response
    // Return a Done response
    Res.LastModified = Buf.st_mtime;
    Res.LastModified = Buf.st_mtime;
-   Res.Size = Buf.st_size;
    Res.TakeHashes(Hash);
    Res.TakeHashes(Hash);
 
 
    URIDone(Res);
    URIDone(Res);
-   
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 1 - 3
methods/http.cc

@@ -97,8 +97,6 @@ void CircleBuf::Reset()
    is non-blocking.. */
    is non-blocking.. */
 bool CircleBuf::Read(int Fd)
 bool CircleBuf::Read(int Fd)
 {
 {
-   unsigned long long BwReadMax;
-
    while (1)
    while (1)
    {
    {
       // Woops, buffer is full
       // Woops, buffer is full
@@ -106,7 +104,7 @@ bool CircleBuf::Read(int Fd)
 	 return true;
 	 return true;
 
 
       // what's left to read in this tick
       // 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) {
       if(CircleBuf::BwReadLimit) {
 	 struct timeval now;
 	 struct timeval now;

+ 5 - 5
methods/https.cc

@@ -21,7 +21,6 @@
 
 
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -405,10 +404,11 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
    curl_easy_getinfo(curl, CURLINFO_FILETIME, &Res.LastModified);
    curl_easy_getinfo(curl, CURLINFO_FILETIME, &Res.LastModified);
    if (Res.LastModified != -1)
    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
    else
       Res.LastModified = resultStat.st_mtime;
       Res.LastModified = resultStat.st_mtime;

+ 1 - 1
methods/https.h

@@ -65,7 +65,7 @@ class HttpsMethod : public pkgAcqMethod
    public:
    public:
    FileFd *File;
    FileFd *File;
       
       
-   HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig) 
+   HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), File(NULL)
    {
    {
       File = 0;
       File = 0;
       curl = curl_easy_init();
       curl = curl_easy_init();

+ 4 - 4
methods/mirror.cc

@@ -114,7 +114,7 @@ bool MirrorMethod::Clean(string Dir)
       for(I=list.begin(); I != list.end(); ++I)
       for(I=list.begin(); I != list.end(); ++I)
       {
       {
 	 string uri = (*I)->GetURI();
 	 string uri = (*I)->GetURI();
-	 if(uri.find("mirror://") != 0)
+	 if(uri.compare(0, strlen("mirror://"), "mirror://") != 0)
 	    continue;
 	    continue;
 	 string BaseUri = uri.substr(0,uri.size()-1);
 	 string BaseUri = uri.substr(0,uri.size()-1);
 	 if (URItoFileName(BaseUri) == Dir->d_name)
 	 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
    // "stable" on the same machine. this is to avoid running into out-of-sync
    // issues (i.e. Release/Release.gpg different on each mirror)
    // issues (i.e. Release/Release.gpg different on each mirror)
    struct utsname buf;
    struct utsname buf;
-   int seed=1, i;
+   int seed=1;
    if(uname(&buf) == 0) {
    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];
          seed = seed * 31 + buf.nodename[i];
       }
       }
    }
    }
@@ -306,7 +306,7 @@ bool MirrorMethod::InitMirrors()
       if (s.size() == 0)
       if (s.size() == 0)
          continue;
          continue;
       // ignore non http lines
       // ignore non http lines
-      if (s.find("http://") != 0)
+      if (s.compare(0, strlen("http://"), "http://") != 0)
          continue;
          continue;
 
 
       AllMirrors.push_back(s);
       AllMirrors.push_back(s);

+ 18 - 18
methods/rsh.cc

@@ -20,7 +20,6 @@
 
 
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -395,13 +394,14 @@ void RSHMethod::SigTerm(int sig)
 {
 {
    if (FailFd == -1)
    if (FailFd == -1)
       _exit(100);
       _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);
    _exit(100);
 }
 }
@@ -488,10 +488,11 @@ bool RSHMethod::Fetch(FetchItem *Itm)
 	 Fd.Close();
 	 Fd.Close();
 
 
 	 // Timestamp
 	 // 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 the file is missing we hard fail otherwise transient fail
 	 if (Missing == true)
 	 if (Missing == true)
@@ -501,18 +502,17 @@ bool RSHMethod::Fetch(FetchItem *Itm)
       }
       }
 
 
       Res.Size = Fd.Size();
       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.LastModified = FailTime;
    Res.TakeHashes(Hash);
    Res.TakeHashes(Hash);
 
 
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(Queue->DestFile.c_str(),&UBuf);
-   FailFd = -1;
-
    URIDone(Res);
    URIDone(Res);
 
 
    return true;
    return true;

+ 12 - 13
methods/server.cc

@@ -17,9 +17,9 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/netrc.h>
 #include <apt-pkg/netrc.h>
 
 
+#include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -368,14 +368,14 @@ void ServerMethod::SigTerm(int)
 {
 {
    if (FailFd == -1)
    if (FailFd == -1)
       _exit(100);
       _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);
    close(FailFd);
-   
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(FailFile.c_str(),&UBuf);
-   
+
    _exit(100);
    _exit(100);
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -539,11 +539,10 @@ int ServerMethod::Loop()
 	    File = 0;
 	    File = 0;
 	    
 	    
 	    // Timestamp
 	    // 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
 	    // Send status to APT
 	    if (Result == true)
 	    if (Result == true)

+ 1 - 1
methods/server.h

@@ -137,7 +137,7 @@ class ServerMethod : public pkgAcqMethod
    virtual ServerState * CreateServerState(URI uri) = 0;
    virtual ServerState * CreateServerState(URI uri) = 0;
    virtual void RotateDNS() = 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() {};
    virtual ~ServerMethod() {};
 };
 };
 
 

+ 4 - 5
test/interactive-helper/rpmver.cc

@@ -2,6 +2,7 @@
 #include <rpm/rpmio.h>
 #include <rpm/rpmio.h>
 #include <rpm/misc.h>
 #include <rpm/misc.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
 
 
 #define xisdigit(x) isdigit(x)
 #define xisdigit(x) isdigit(x)
@@ -12,10 +13,8 @@ using namespace std;
 
 
 int rpmvercmp(const char * a, const char * b)
 int rpmvercmp(const char * a, const char * b)
 {
 {
-    char oldch1, oldch2;
     char * str1, * str2;
     char * str1, * str2;
     char * one, * two;
     char * one, * two;
-    int rc;
     int isnum;
     int isnum;
 
 
     /* easy comparison to see if versions are identical */
     /* 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 */
 	/* save character at the end of the alpha or numeric segment */
 	/* so that they can be restored after the comparison */
 	/* so that they can be restored after the comparison */
-	oldch1 = *str1;
+	char oldch1 = *str1;
 	*str1 = '\0';
 	*str1 = '\0';
-	oldch2 = *str2;
+	char oldch2 = *str2;
 	*str2 = '\0';
 	*str2 = '\0';
 
 
 	/* take care of the case where the two version segments are */
 	/* 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  */
 	/* segments are alpha or if they are numeric.  don't return  */
 	/* if they are equal because there might be more segments to */
 	/* if they are equal because there might be more segments to */
 	/* compare */
 	/* compare */
-	rc = strcmp(one, two);
+	int rc = strcmp(one, two);
 	if (rc) return rc;
 	if (rc) return rc;
 
 
 	/* restore character that was replaced by null above */
 	/* restore character that was replaced by null above */