*/
#include <errno.h>
-#include <fstream>
#include <iostream>
#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
+#include <msp/io/file.h>
#include "builder.h"
#include "copy.h"
#include "package.h"
}
}
- ifstream in(copy.src.str().c_str());
- if(!in)
+ try
{
- cerr<<"Can't open "<<copy.src<<" for reading\n";
- done=error=true;
- return;
- }
+ IO::File in(copy.src.str());
+ IO::File out(copy.dest.str(), IO::M_WRITE);
- ofstream out(copy.dest.str().c_str());
- if(!out)
+ // Actual transfer loop
+ char buf[16384];
+ while(!in.eof())
+ {
+ unsigned len=in.read(buf, sizeof(buf));
+ out.write(buf, len);
+ }
+ }
+ catch(const Exception &e)
{
- cerr<<"Can't open "<<copy.dest<<" for writing\n";
+ cerr<<e.what()<<'\n';
done=error=true;
return;
}
- // Actual transfer loop
- char buf[16384];
- while(!in.eof())
- {
- in.read(buf, sizeof(buf));
- out.write(buf, in.gcount());
- }
-
// Preserve file permissions
struct stat st=FS::stat(copy.src);
chmod(copy.dest.str().c_str(), st.st_mode&0777);