-#include <fstream>
-#include <msp/path/utils.h>
-#include "copy.h"
-#include "package.h"
-
-using namespace std;
-using namespace Msp;
-
-Copy::Copy(Builder &b, const Package &pkg, const Path::Path &s, const Path::Path &d):
- Action(b),
- src(s),
- dest(d),
- worker(*this)
-{
- announce(pkg.get_name(), "INST", dest[-1]);
-}
-
-int Copy::check()
-{
- if(worker.get_done())
- {
- signal_done.emit();
- worker.join();
- return 0;
- }
- return -1;
-}
-
-void Copy::Worker::main()
-{
- Path::mkpath(copy.src.subpath(0, copy.src.size()-1), 0755);
- unlink(copy.dest.str().c_str());
- ifstream in(copy.src.str().c_str());
- ofstream out(copy.dest.str().c_str());
-
- char buf[16384];
- while(!in.eof())
- {
- in.read(buf, sizeof(buf));
- out.write(buf, in.gcount());
- }
-
- struct stat st;
- Path::stat(copy.src, st);
- chmod(copy.dest.str().c_str(), st.st_mode&0777);
-
- done=true;
-}