aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/conditionfiletime.cpp17
-rw-r--r--src/runner.cpp4
-rw-r--r--src/statcache.cpp28
-rw-r--r--src/statcache.h24
4 files changed, 64 insertions, 9 deletions
diff --git a/src/conditionfiletime.cpp b/src/conditionfiletime.cpp
index 148ffac..abcb3f3 100644
--- a/src/conditionfiletime.cpp
+++ b/src/conditionfiletime.cpp
@@ -4,6 +4,7 @@
4#include <sys/types.h> 4#include <sys/types.h>
5#include <sys/stat.h> 5#include <sys/stat.h>
6#include <unistd.h> 6#include <unistd.h>
7#include "statcache.h"
7 8
8#include <bu/sio.h> 9#include <bu/sio.h>
9using namespace Bu; 10using namespace Bu;
@@ -18,6 +19,7 @@ ConditionFileTime::~ConditionFileTime()
18 19
19bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget ) 20bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
20{ 21{
22 StatCache &Stat = StatCache::getInstance();
21 for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) 23 for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ )
22 { 24 {
23 if( access( (*j).getStr(), F_OK ) ) 25 if( access( (*j).getStr(), F_OK ) )
@@ -30,22 +32,20 @@ bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
30 } 32 }
31 } 33 }
32 34
33 time_t tOut = 0; 35 time_t tOut = 0, tmp;
34 struct stat s;
35 for( StrList::const_iterator j = rTarget.getOutputList().begin(); 36 for( StrList::const_iterator j = rTarget.getOutputList().begin();
36 j; j++ ) 37 j; j++ )
37 { 38 {
38 stat( (*j).getStr(), &s ); 39 tmp = Stat.mtime( *j );
39 if( tOut == 0 || tOut > s.st_mtime ) 40 if( tOut == 0 || tOut > tmp )
40 { 41 {
41 tOut = s.st_mtime; 42 tOut = tmp;
42 } 43 }
43 } 44 }
44 for( StrList::const_iterator j = rTarget.getInputList().begin(); 45 for( StrList::const_iterator j = rTarget.getInputList().begin();
45 j; j++ ) 46 j; j++ )
46 { 47 {
47 stat( (*j).getStr(), &s ); 48 if( tOut < Stat.mtime( *j ) )
48 if( tOut < s.st_mtime )
49 { 49 {
50 //sio << "-- Target processed because '" << *j 50 //sio << "-- Target processed because '" << *j
51 // << "' is newer than output." << sio.nl; 51 // << "' is newer than output." << sio.nl;
@@ -57,8 +57,7 @@ bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
57 for( StrList::const_iterator j = rTarget.getRequiresList().begin(); 57 for( StrList::const_iterator j = rTarget.getRequiresList().begin();
58 j; j++ ) 58 j; j++ )
59 { 59 {
60 stat( (*j).getStr(), &s ); 60 if( tOut < Stat.mtime( *j ) )
61 if( tOut < s.st_mtime )
62 { 61 {
63 //sio << "-- Target processed because '" << *j 62 //sio << "-- Target processed because '" << *j
64 // << "' is newer than output." << sio.nl; 63 // << "' is newer than output." << sio.nl;
diff --git a/src/runner.cpp b/src/runner.cpp
index ace9ce9..947f2f5 100644
--- a/src/runner.cpp
+++ b/src/runner.cpp
@@ -417,6 +417,10 @@ Variable Runner::run( AstBranch::NodeList::const_iterator n )
417 ); 417 );
418 } 418 }
419 break; 419 break;
420
421 case AstNode::typePushPrefix:
422 case AstNode::typePopPrefix:
423 break;
420/* 424/*
421 case AstNode::typeCondition: 425 case AstNode::typeCondition:
422 if( pCurTarget ) 426 if( pCurTarget )
diff --git a/src/statcache.cpp b/src/statcache.cpp
new file mode 100644
index 0000000..3f5c21f
--- /dev/null
+++ b/src/statcache.cpp
@@ -0,0 +1,28 @@
1#include "statcache.h"
2
3#include <sys/stat.h>
4
5#include <bu/sio.h>
6
7StatCache::StatCache()
8{
9}
10
11StatCache::~StatCache()
12{
13}
14
15time_t StatCache::mtime( const Bu::FString &sFileName )
16{
17 try
18 {
19 return hMTime.get( sFileName );
20 } catch( ... )
21 {
22 struct stat s;
23 stat( sFileName.getStr(), &s );
24 hMTime.insert( sFileName, s.st_mtime );
25 return s.st_mtime;
26 }
27}
28
diff --git a/src/statcache.h b/src/statcache.h
new file mode 100644
index 0000000..e081ec3
--- /dev/null
+++ b/src/statcache.h
@@ -0,0 +1,24 @@
1#ifndef STAT_CACHE_H
2#define STAT_CACHE_H
3
4#include <bu/hash.h>
5#include <bu/singleton.h>
6#include <bu/fstring.h>
7#include <time.h>
8
9class StatCache : public Bu::Singleton<StatCache>
10{
11friend class Bu::Singleton<StatCache>;
12private:
13 StatCache();
14 virtual ~StatCache();
15
16public:
17 time_t mtime( const Bu::FString &sFileName );
18
19private:
20 typedef Bu::Hash<Bu::FString, time_t> TimeHash;
21 TimeHash hMTime;
22};
23
24#endif