X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcopy.cpp;h=2d2a7ca9c023c557954e05924d9181f4280dae97;hb=HEAD;hp=9bca33f3050989900407937c3fd68bb0536f76c6;hpb=36c90dafd6ff514919b802ccb54404b882afc944;p=builder.git diff --git a/source/copy.cpp b/source/copy.cpp deleted file mode 100644 index 9bca33f..0000000 --- a/source/copy.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef _WIN32 -#include -#include -#endif -#include -#include -#include -#include -#include -#include "builder.h" -#include "copy.h" -#include "installedfile.h" -#include "internaltask.h" - -using namespace std; -using namespace Msp; - -Target *Copy::create_target(const vector &sources, const string &arg) -{ - FileTarget &file_tgt = dynamic_cast(*sources.front()); - InstalledFile *inst = new InstalledFile(builder, *file_tgt.get_package(), file_tgt, arg); - inst->set_tool(*this); - return inst; -} - -Task *Copy::run(const Target &target) const -{ - const InstalledFile &install = dynamic_cast(target); - return new InternalTask([&install]{ return _run(install); }); -} - -bool Copy::_run(const InstalledFile &install) -{ - const FileTarget &source = install.get_source(); - const FS::Path &src_path = source.get_path(); - const FS::Path &dst_path = install.get_path(); - - try - { - IO::File in(src_path.str()); - IO::File out(dst_path.str(), IO::M_WRITE); - - // Actual transfer loop - char buf[16384]; - while(!in.eof()) - { - unsigned len = in.read(buf, sizeof(buf)); - out.write(buf, len); - } - } - catch(const exception &e) - { - IO::print(IO::cerr, "%s\n", e.what()); - return false; - } - -#ifndef _WIN32 - // Preserve file permissions - struct stat st; - if(stat(src_path.str().c_str(), &st)==0) - chmod(dst_path.str().c_str(), st.st_mode&0777); - - const FS::Path &link = install.get_symlink(); - if(!link.empty()) - { - FS::Path relpath = FS::relative(dst_path, FS::dirname(link)); - if(FS::exists(link)) - FS::unlink(link); - symlink(relpath.str().c_str(), link.str().c_str()); - } -#endif - - return true; -}