]> git.tdb.fi Git - builder.git/blobdiff - source/dependencycache.cpp
Further changes for library compatibility
[builder.git] / source / dependencycache.cpp
index 85ed4fd656b20a74746e0513d7dd11e13c2ad365..f691d540190f65da3444ec97823562b3fb05afcd 100644 (file)
@@ -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 <fstream>
-#include <msp/path/utils.h>
+#include <msp/core/maputils.h>
+#include <msp/fs/stat.h>
+#include <msp/io/file.h>
+#include <msp/io/print.h>
 #include <msp/strings/utils.h>
 #include "builder.h"
 #include "dependencycache.h"
@@ -20,58 +22,50 @@ 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;
+       return get_item(deps, tgt);
 }
 
-/**
-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<<i->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<string> parts=split(line, '|');
-               deps[parts[0]]=StringList(parts.begin()+1, parts.end());
-       }
+               IO::BufferedFile in(fn);
+
+               string line;
+               while(in.getline(line))
+               {
+                       vector<string> parts = split(line, '|');
+                       deps[parts[0]] = StringList(parts.begin()+1, parts.end());
+               }
 
-       mtime=Time::TimeStamp::from_unixtime(stat(fn).st_mtime);
+               mtime = FS::stat(fn).get_modify_time();
+       }
+       catch(const IO::file_not_found &)
+       { }
 }