Distributed under the LGPL
*/
-#include <fstream>
#include <msp/fs/stat.h>
+#include <msp/io/except.h>
+#include <msp/io/file.h>
+#include <msp/io/print.h>
#include <msp/strings/utils.h>
#include "builder.h"
#include "dependencycache.h"
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 line;
- while(getline(in, line))
+ try
{
- vector<string> parts=split(line, '|');
- deps[parts[0]]=StringList(parts.begin()+1, parts.end());
- }
+ IO::BufferedFile in(fn);
- mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
+ 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(FS::stat(fn).st_mtime);
+ }
+ catch(const IO::FileNotFound &)
+ { }
}