diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/conditionfiletime.cpp | 17 | ||||
-rw-r--r-- | src/statcache.cpp | 28 | ||||
-rw-r--r-- | src/statcache.h | 24 |
3 files changed, 9 insertions, 60 deletions
diff --git a/src/conditionfiletime.cpp b/src/conditionfiletime.cpp index abcb3f3..148ffac 100644 --- a/src/conditionfiletime.cpp +++ b/src/conditionfiletime.cpp | |||
@@ -4,7 +4,6 @@ | |||
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" | ||
8 | 7 | ||
9 | #include <bu/sio.h> | 8 | #include <bu/sio.h> |
10 | using namespace Bu; | 9 | using namespace Bu; |
@@ -19,7 +18,6 @@ ConditionFileTime::~ConditionFileTime() | |||
19 | 18 | ||
20 | bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget ) | 19 | bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget ) |
21 | { | 20 | { |
22 | StatCache &Stat = StatCache::getInstance(); | ||
23 | for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) | 21 | for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) |
24 | { | 22 | { |
25 | if( access( (*j).getStr(), F_OK ) ) | 23 | if( access( (*j).getStr(), F_OK ) ) |
@@ -32,20 +30,22 @@ bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget ) | |||
32 | } | 30 | } |
33 | } | 31 | } |
34 | 32 | ||
35 | time_t tOut = 0, tmp; | 33 | time_t tOut = 0; |
34 | struct stat s; | ||
36 | for( StrList::const_iterator j = rTarget.getOutputList().begin(); | 35 | for( StrList::const_iterator j = rTarget.getOutputList().begin(); |
37 | j; j++ ) | 36 | j; j++ ) |
38 | { | 37 | { |
39 | tmp = Stat.mtime( *j ); | 38 | stat( (*j).getStr(), &s ); |
40 | if( tOut == 0 || tOut > tmp ) | 39 | if( tOut == 0 || tOut > s.st_mtime ) |
41 | { | 40 | { |
42 | tOut = tmp; | 41 | tOut = s.st_mtime; |
43 | } | 42 | } |
44 | } | 43 | } |
45 | for( StrList::const_iterator j = rTarget.getInputList().begin(); | 44 | for( StrList::const_iterator j = rTarget.getInputList().begin(); |
46 | j; j++ ) | 45 | j; j++ ) |
47 | { | 46 | { |
48 | if( tOut < Stat.mtime( *j ) ) | 47 | stat( (*j).getStr(), &s ); |
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,7 +57,8 @@ 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 | if( tOut < Stat.mtime( *j ) ) | 60 | stat( (*j).getStr(), &s ); |
61 | if( tOut < s.st_mtime ) | ||
61 | { | 62 | { |
62 | //sio << "-- Target processed because '" << *j | 63 | //sio << "-- Target processed because '" << *j |
63 | // << "' is newer than output." << sio.nl; | 64 | // << "' is newer than output." << sio.nl; |
diff --git a/src/statcache.cpp b/src/statcache.cpp deleted file mode 100644 index 3f5c21f..0000000 --- a/src/statcache.cpp +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | #include "statcache.h" | ||
2 | |||
3 | #include <sys/stat.h> | ||
4 | |||
5 | #include <bu/sio.h> | ||
6 | |||
7 | StatCache::StatCache() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | StatCache::~StatCache() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | time_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 deleted file mode 100644 index e081ec3..0000000 --- a/src/statcache.h +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
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 | |||
9 | class StatCache : public Bu::Singleton<StatCache> | ||
10 | { | ||
11 | friend class Bu::Singleton<StatCache>; | ||
12 | private: | ||
13 | StatCache(); | ||
14 | virtual ~StatCache(); | ||
15 | |||
16 | public: | ||
17 | time_t mtime( const Bu::FString &sFileName ); | ||
18 | |||
19 | private: | ||
20 | typedef Bu::Hash<Bu::FString, time_t> TimeHash; | ||
21 | TimeHash hMTime; | ||
22 | }; | ||
23 | |||
24 | #endif | ||