libzypp  11.13.5
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 
24 namespace parser
25 {
26 
27 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