X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftar.cpp;h=07c14ce9282f3dcab5cf26bc2aaae46acc43501d;hb=1ed833343bc83b83c5f61cbfd74423bbba677a04;hp=75018fb0850b138c93b00d4fad09595f7643490f;hpb=5622fc20f0be8bff0938d24f6f45d3ab384288ca;p=builder.git diff --git a/source/tar.cpp b/source/tar.cpp index 75018fb..07c14ce 100644 --- a/source/tar.cpp +++ b/source/tar.cpp @@ -1,16 +1,10 @@ -/* $Id$ - -This file is part of builder -Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include #include #include #include "builder.h" +#include "internaltask.h" #include "sourcepackage.h" #include "tar.h" #include "tarball.h" @@ -18,85 +12,84 @@ Distributed under the LGPL using namespace std; using namespace Msp; -Tar::Tar(Builder &b, const TarBall &t): - InternalAction(b), - tarball(t) +Tar::Tar(Builder &b): + Tool(b, "TAR") { - string basename=FS::basename(tarball.get_path()); - announce(tarball.get_package()->get_name(), "TAR ", basename); - if(builder.get_verbose()>=2) - IO::print("Create %s\n", basename); - - if(!builder.get_dry_run()) - worker=new Worker(*this); + processing_unit = COMPONENT; + set_run_internal(&_run); } - -Tar::Worker::Worker(Tar &t): - tar(t) +Target *Tar::create_target(const vector &sources, const string &arg) { - launch(); + if(sources.empty() || !sources.front()->get_package()) + throw invalid_argument("Tar::create_target"); + + TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg); + for(Target *s: sources) + tarball->add_dependency(*s); + + tarball->set_tool(*this); + + return tarball; } -void Tar::Worker::main() +bool Tar::_run(const TarBall &tarball) { - const FS::Path &pkg_src=tar.tarball.get_package()->get_source(); - FS::Path basedir=FS::basepart(FS::basename(tar.tarball.get_path())); + const FS::Path &pkg_src = tarball.get_package()->get_source_directory(); + FS::Path basedir = FS::basepart(FS::basename(tarball.get_path())); - IO::File out(tar.tarball.get_path().str(), IO::M_WRITE); - const TargetList &deps=tar.tarball.get_depends(); - for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i) + IO::File out(tarball.get_path().str(), IO::M_WRITE); + for(Target *d: tarball.get_dependencies()) { - FileTarget *ft=dynamic_cast(*i); + FileTarget *ft = dynamic_cast(d); if(!ft) continue; char buf[4096]; memset(buf, 0, 512); - string rel_path=(basedir/relative(ft->get_path(), pkg_src)).str(); + string rel_path = (basedir/relative(ft->get_path(), pkg_src)).str(); if(rel_path.size()>99) { IO::print("Can't store %s in tar archive - too long name\n", rel_path); - error=true; - break; + return false; } memcpy(buf, rel_path.data(), rel_path.size()); - struct stat st=FS::stat(ft->get_path()); - store_number(buf+100, st.st_mode, 7); - store_number(buf+108, st.st_uid, 7); - store_number(buf+116, st.st_gid, 7); - store_number(buf+124, st.st_size, 11); - store_number(buf+136, st.st_mtime, 11); - buf[156]='0'; + FS::Stat st = FS::stat(ft->get_path()); + store_number(buf+100, 0666, 7); + store_number(buf+108, 0, 7); + store_number(buf+116, 0, 7); + store_number(buf+124, st.get_size(), 11); + store_number(buf+136, st.get_modify_time().to_unixtime(), 11); + buf[156] = '0'; memset(buf+148, ' ', 8); - unsigned chk=0; + unsigned chk = 0; for(unsigned j=0; j<512; ++j) - chk+=static_cast(buf[j]); + chk += static_cast(buf[j]); store_number(buf+148, chk, 7); - buf[155]=0; + buf[155] = 0; out.write(buf, 512); IO::File in(ft->get_path().str()); - for(int j=0; j