X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdependencycache.cpp;h=ffc6fd63fbc7291c289395f9230abc78a83378ca;hb=75bdcf13fbd285e2006337ec606ca28fa4ddae9e;hp=85ed4fd656b20a74746e0513d7dd11e13c2ad365;hpb=4d0d003b022943d8a0e39ba19078bab8d32d8857;p=builder.git diff --git a/source/dependencycache.cpp b/source/dependencycache.cpp index 85ed4fd..ffc6fd6 100644 --- a/source/dependencycache.cpp +++ b/source/dependencycache.cpp @@ -1,12 +1,14 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include -#include +#include +#include +#include +#include #include #include "builder.h" #include "dependencycache.h" @@ -20,58 +22,54 @@ DependencyCache::DependencyCache(SourcePackage &p): changed(false) { } -const StringList &DependencyCache::get_deps(const string &tgt) const +void DependencyCache::set_deps(const string &tgt, const StringList &d) { - DepsMap::const_iterator i=deps.find(tgt); - if(i==deps.end()) - { - static StringList dummy; - return dummy; - } - return i->second; + deps[tgt] = d; + changed = true; } -void DependencyCache::set_deps(const string &tgt, const StringList &d) +const StringList &DependencyCache::get_deps(const string &tgt) const { - deps[tgt]=d; - changed=true; + DepsMap::const_iterator i = deps.find(tgt); + if(i==deps.end()) + throw KeyError("Unknown dependencies", tgt); + + return i->second; } -/** -Saves the depencency cache. If there are no cached dependencies or they -haven't been changed, does nothing. -*/ void DependencyCache::save() const { if(deps.empty() || !changed || package.get_builder().get_dry_run()) return; - ofstream out((package.get_source()/".deps").str().c_str()); - if(!out) - return; + IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE); for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i) { - out<first; + IO::print(out, i->first); for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j) - out<<'|'<<*j; - out<<'\n'; + IO::print(out, "|%s", *j); + IO::print(out, "\n"); } } void DependencyCache::load() { - string fn=(package.get_source()/".deps").str(); - ifstream in(fn.c_str()); - if(!in) - return; + string fn = (package.get_source()/".deps").str(); - string line; - while(getline(in, line)) + try { - vector parts=split(line, '|'); - deps[parts[0]]=StringList(parts.begin()+1, parts.end()); - } + IO::BufferedFile in(fn); - mtime=Time::TimeStamp::from_unixtime(stat(fn).st_mtime); + string line; + while(in.getline(line)) + { + vector parts = split(line, '|'); + deps[parts[0]] = StringList(parts.begin()+1, parts.end()); + } + + mtime = Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime); + } + catch(const IO::FileNotFound &) + { } }