libzypp  13.10.6
RepoParser.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include <iostream>
11 #include "zypp/base/Logger.h"
12 #include "zypp/base/String.h"
13 
14 #include "zypp/PathInfo.h"
15 
17 
18 using std::endl;
19 
21 namespace zypp
22 {
23 namespace parser
25 {
26 namespace plaindir
28 {
29 
30 static void recursive_timestamp( const Pathname &dir, time_t & max )
31 {
32  std::list<std::string> dircontent;
33  if ( filesystem::readdir( dircontent, dir, false/*no dots*/ ) != 0 )
34  return; // readdir logged the error
35 
36  for_( it, dircontent.begin(), dircontent.end() )
37  {
38  PathInfo pi( dir + *it, PathInfo::LSTAT );
39  if ( pi.isDir() )
40  {
41  recursive_timestamp( pi.path(), max );
42  if ( pi.mtime() > max )
43  max = pi.mtime();
44  }
45  }
46 }
47 
48 RepoStatus dirStatus( const Pathname &dir )
49 {
50  time_t t = 0;
51  PathInfo pi(dir);
52  if ( pi.isDir() )
53  {
54  t = pi.mtime();
55  recursive_timestamp(dir,t);
56  }
57  RepoStatus status;
58  status.setTimestamp(Date(t));
59  status.setChecksum(str::numstring(t));
60  return status;
61 }
62 
64 } // namespace plaindir
67 } // namespace parser
70 } // namespace zypp
static void recursive_timestamp(const Pathname &dir, time_t &max)
Definition: RepoParser.cc:30
RepoStatus & setTimestamp(const Date &timestamp)
set the repository timestamp
Definition: RepoStatus.cc:135
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
RepoStatus dirStatus(const Pathname &dir)
Gives a cookie for a dir.
Definition: RepoParser.cc:48
Store and operate on date (time_t).
Definition: Date.h:31
std::string numstring(char n, int w=0)
Definition: String.h:219
RepoStatus & setChecksum(const std::string &checksum)
set the repository checksum
Definition: RepoStatus.cc:129
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Definition: PathInfo.cc:599
Local facts about a repository This class represents the status of a repository on the system...
Definition: RepoStatus.h:37