X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tool%2Fpacker.cpp;h=46dd5d242ffc652cf9547bf7eb68bb76bb946a19;hb=ffbc4b86547b788225895a868b48d602cb1bc139;hp=44be7243e86e45df093e8fdf38270f8bcdfbbd45;hpb=a3935faaba6187cbccc5f2b60b065d9180b1cdee;p=libs%2Fdatafile.git diff --git a/tool/packer.cpp b/tool/packer.cpp index 44be724..46dd5d2 100644 --- a/tool/packer.cpp +++ b/tool/packer.cpp @@ -19,17 +19,20 @@ Packer::Packer(DataTool &t): IO::File *Packer::tempfile() { + FS::Path tmpdir; + const char *tmp_env = getenv("TMPDIR"); + if(tmp_env) + tmpdir = tmp_env; + else + tmpdir = "/tmp"; + for(unsigned i=0;; ++i) { try { - std::string filename = format("/tmp/mspdatatool.%d", i); - /*filename.reserve(25); - filename.append("/tmp/mspdatatool."); - for(unsigned i=0; i<8; ++i) - filename.append(rand());*/ - IO::File *file = new IO::File(filename, IO::M_RDWR, IO::File::C_NEW); - FS::unlink(filename); + FS::Path filename = tmpdir/format("mspdatatool.%d", i); + IO::File *file = new IO::File(filename.str(), IO::M_RDWR, IO::File::C_NEW); + FS::unlink(filename.str()); return file; } catch(const IO::file_already_exists &) @@ -79,7 +82,7 @@ bool Packer::detect_raw(IO::Seekable &in) IO::SeekOffset offset = in.tell(); bool raw = false; DataFile::Parser parser(in, "-"); - while(!raw && !in.eof() && in.tell()<10240) + while(!raw && parser && in.tell()<10240) { try { @@ -106,8 +109,7 @@ void Packer::transfer_datafile(IO::Base &in, const string &fn, IO::Base &out, Ob DataFile::Statement st = parser.parse(true); if(st.valid) { - bool sys = !st.keyword.compare(0, 2, "__"); - if(collection && !sys) + if(collection && !st.control) { if(st.get_signature()=="s") { @@ -119,7 +121,7 @@ void Packer::transfer_datafile(IO::Base &in, const string &fn, IO::Base &out, Ob else collection = false; } - if(!sys || st.keyword=="__src") + if(!st.control || st.keyword=="__src") writer->write(st); } }