[devel] [PATCH for apt 25/38] Check subsecond modification time for cached files

Aleksei Nikiforov darktemplar на altlinux.org
Вт Дек 10 18:23:30 MSK 2019


---
 apt/apt-pkg/pkgcache.cc         | 2 +-
 apt/apt-pkg/pkgcache.h          | 1 +
 apt/apt-pkg/rpm/rpmhandler.cc   | 3 ++-
 apt/apt-pkg/rpm/rpmhandler.h    | 2 ++
 apt/apt-pkg/rpm/rpmindexfile.cc | 8 +++++---
 apt/apt-pkg/rpm/rpmsystem.cc    | 3 ++-
 6 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/apt/apt-pkg/pkgcache.cc b/apt/apt-pkg/pkgcache.cc
index 9965532..c9f4cfd 100644
--- a/apt/apt-pkg/pkgcache.cc
+++ b/apt/apt-pkg/pkgcache.cc
@@ -638,7 +638,7 @@ bool pkgCache::PkgFileIterator::IsOk()
    if (stat(FileName(),&Buf) != 0)
       return false;
 
-   if (Buf.st_size != (signed)File->Size || Buf.st_mtime != File->mtime)
+   if (Buf.st_size != (signed)File->Size || Buf.st_mtim.tv_sec != File->mtime || Buf.st_mtim.tv_nsec != File->mnanotime)
       return false;
 
    return true;
diff --git a/apt/apt-pkg/pkgcache.h b/apt/apt-pkg/pkgcache.h
index 56fc89d..05a63bc 100644
--- a/apt/apt-pkg/pkgcache.h
+++ b/apt/apt-pkg/pkgcache.h
@@ -250,6 +250,7 @@ struct pkgCache::PackageFile
    map_ptrloc NextFile;        // PackageFile
    unsigned short ID;
    time_t mtime;                  // Modification time for the file
+   time_t mnanotime;           // Subsecond modification time for the file
 };
 
 struct pkgCache::VerFile
diff --git a/apt/apt-pkg/rpm/rpmhandler.cc b/apt/apt-pkg/rpm/rpmhandler.cc
index 46f7e0b..0bc6b4e 100644
--- a/apt/apt-pkg/rpm/rpmhandler.cc
+++ b/apt/apt-pkg/rpm/rpmhandler.cc
@@ -396,7 +396,8 @@ RPMDBHandler::RPMDBHandler(bool WriteLock)
    // restore the mtime and save our cache.
    struct stat St;
    stat(DataPath(false).c_str(), &St);
-   DbFileMtime = St.st_mtime;
+   DbFileMtime = St.st_mtim.tv_sec;
+   DbFileMnanotime = St.st_mtim.tv_nsec;
 
 #if RPM_VERSION >= 0x040100
    Handler = rpmtsCreate();
diff --git a/apt/apt-pkg/rpm/rpmhandler.h b/apt/apt-pkg/rpm/rpmhandler.h
index 196cd97..7d77603 100644
--- a/apt/apt-pkg/rpm/rpmhandler.h
+++ b/apt/apt-pkg/rpm/rpmhandler.h
@@ -119,6 +119,7 @@ class RPMDBHandler : public RPMHandler
    bool WriteLock;
 
    time_t DbFileMtime;
+   time_t DbFileMnanotime;
 
    public:
 
@@ -129,6 +130,7 @@ class RPMDBHandler : public RPMHandler
    virtual inline bool IsDatabase() override {return true;};
    virtual bool HasWriteLock() {return WriteLock;};
    virtual time_t Mtime() {return DbFileMtime;}
+   virtual time_t Mnanotime() {return DbFileMnanotime;}
    virtual bool OrderedOffset() override {return false;};
 
    RPMDBHandler(bool WriteLock=false);
diff --git a/apt/apt-pkg/rpm/rpmindexfile.cc b/apt/apt-pkg/rpm/rpmindexfile.cc
index ad011a7..a92e60f 100644
--- a/apt/apt-pkg/rpm/rpmindexfile.cc
+++ b/apt/apt-pkg/rpm/rpmindexfile.cc
@@ -383,7 +383,8 @@ bool rpmPkgListIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
       return _error->Errno("stat",_("Failed to stat %s"), PackageFile.c_str());
    }
    File->Size = St.st_size;
-   File->mtime = St.st_mtime;
+   File->mtime = St.st_mtim.tv_sec;
+   File->mnanotime = St.st_mtim.tv_nsec;
    
    rpmListParser Parser(Handler);
    if (_error->PendingError() == true) 
@@ -452,7 +453,7 @@ pkgCache::PkgFileIterator rpmPkgListIndex::FindInCache(pkgCache &Cache) const
       if (stat(File.FileName(),&St) != 0)
 	 return pkgCache::PkgFileIterator(Cache);
 
-      if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
+      if ((unsigned)St.st_size != File->Size || St.st_mtim.tv_sec != File->mtime || St.st_mtim.tv_nsec != File->mnanotime)
 	 return pkgCache::PkgFileIterator(Cache);
       return File;
    }
@@ -586,6 +587,7 @@ bool rpmDatabaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
       return _error->Errno("fstat",_("Failed to stat %s"), Handler->DataPath(false).c_str());
    CFile->Size = St.st_size;
    CFile->mtime = Handler->Mtime();
+   CFile->mnanotime = Handler->Mnanotime();
    
    if (Gen.MergeList(Parser) == false)
       return _error->Error(_("Problem with MergeList %s"),
@@ -624,7 +626,7 @@ pkgCache::PkgFileIterator rpmDatabaseIndex::FindInCache(pkgCache &Cache) const
       struct stat St;
       if (stat(File.FileName(),&St) != 0)
 	 return pkgCache::PkgFileIterator(Cache);
-      if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
+      if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime || St.st_mtim.tv_nsec != File->mnanotime)
 	 return pkgCache::PkgFileIterator(Cache);
       return File;
    }   
diff --git a/apt/apt-pkg/rpm/rpmsystem.cc b/apt/apt-pkg/rpm/rpmsystem.cc
index fff2111..e48267c 100644
--- a/apt/apt-pkg/rpm/rpmsystem.cc
+++ b/apt/apt-pkg/rpm/rpmsystem.cc
@@ -486,7 +486,8 @@ static void HashOptionFile(unsigned long &Hash, const char *Name)
    string FileName = _config->FindFile(Name);
    struct stat st;
    stat(FileName.c_str(), &st);
-   Hash += st.st_mtime;
+   Hash += st.st_mtim.tv_sec;
+   Hash += st.st_mtim.tv_nsec;
 }
 unsigned long rpmSystem::OptionsHash() const
 {
-- 
2.24.0



Подробная информация о списке рассылки Devel