X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcopy.cpp;h=24be942532b83ab52a0dcfdeb8446ad29d708edf;hb=c75c89d2425ab0c69e94d45a5d956286838bbc67;hp=cdbbd48f1eead0b7c399a4b7ec7ad534252be2c4;hpb=5504b35e6c6cfb1cfa098b94e31cda173cc0482a;p=builder.git diff --git a/source/copy.cpp b/source/copy.cpp index cdbbd48..24be942 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -1,73 +1,96 @@ -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include "builder.h" #include "copy.h" -#include "package.h" +#include "installedfile.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) +Copy::Copy(Builder &b): + Tool(b, "CP") +{ } + +Target *Copy::create_target(const list &sources, const string &arg) { - announce(pkg.get_name(), "INST", dest[-1]); - if(builder.get_verbose()>=2) - cout< "<(*sources.front()); + InstalledFile *inst = new InstalledFile(builder, *file_tgt.get_package(), file_tgt, arg); + inst->set_tool(*this); + return inst; } -int Copy::check() +Task *Copy::run(const Target &target) const { - if(worker.get_done()) - { - signal_done.emit(); - worker.join(); - return worker.get_error()?1:0; - } - return -1; + const InstalledFile &install = dynamic_cast(target); + Worker *worker = new Worker(install); + return new InternalTask(worker); } + +Copy::Worker::Worker(const InstalledFile &t): + target(t) +{ } + void Copy::Worker::main() { - Path::mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755); - - if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT) + const FileTarget &source = target.get_source(); + const FS::Path &src_path = source.get_path(); + const FS::Path &dst_path = target.get_path(); + FS::mkpath(FS::dirname(dst_path), 0755); + + // Remove old file. Not doing this would cause Bad Stuff when installing libraries. + if(FS::exists(dst_path)) { - int err=errno; - cerr<<"Can't unlink "<