diff options
author | pixel <pixel> | 2003-01-28 17:36:57 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-01-28 17:36:57 +0000 |
commit | bab663b9012d3dc2be6afe930cb7193957404307 (patch) | |
tree | 7470a903c047f00050bd3a72251d6664695dfbaf | |
parent | 715e5efccac0144c48a2f8ae0c8b959506f74a9f (diff) |
Commit of the day.
-rw-r--r-- | include/CopyJob.h | 6 | ||||
-rw-r--r-- | lib/CopyJob.cc | 14 | ||||
-rw-r--r-- | src/paq.cc | 48 |
3 files changed, 59 insertions, 9 deletions
diff --git a/include/CopyJob.h b/include/CopyJob.h index 8e4135c..7284b24 100644 --- a/include/CopyJob.h +++ b/include/CopyJob.h @@ -1,6 +1,7 @@ #ifndef __COPYJOB_H__ #define __COPYJOB_H__ +#include <sys/time.h> #include <Task.h> #include <Handle.h> @@ -8,7 +9,7 @@ class CopyJob : public Task { public: - CopyJob(Handle *, Handle *, ssize_t = -1, bool = false, bool = false); + CopyJob(Handle *, Handle *, ssize_t = -1, bool = false, bool = false, int = -1); virtual ~CopyJob(); virtual int Do() throw (GeneralException); virtual String GetName(); @@ -18,7 +19,8 @@ class CopyJob : public Task { bool ds, dd; ssize_t siz, cursiz; char buffer[COPY_BUFSIZ + 1]; - int r, w, tw; + int r, w, tw, shape; + struct timeval start; }; #endif diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 329dd63..2554654 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -4,10 +4,16 @@ #include "gettext.h" #include "CopyJob.h" -CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, bool add) : s(as), d(ad), ds(ads), dd(add), siz(asiz), cursiz(0), r(0), w(0), tw(0) { +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, bool add, int ashape) : s(as), d(ad), ds(ads), dd(add), siz(asiz), cursiz(0), r(0), w(0), tw(0), shape(ashape) { + struct timezone tz; + s->SetNonBlock(); d->SetNonBlock(); WaitFor(s, W4_READING); + + if (shape > 0) { + gettimeofday(&start, &tz); + } } CopyJob::~CopyJob() { @@ -22,6 +28,12 @@ CopyJob::~CopyJob() { int CopyJob::Do() throw (GeneralException) { int tr; + struct timeval now; + struct timezone tz; + + if (shape > 0) { + gettimeofday(&now, &tz); + } switch (current) { case 0: @@ -1,5 +1,7 @@ #include <dirent.h> +#include <unistd.h> #include <iostream.h> +#include <list> #include <Main.h> #include <Input.h> #include <Output.h> @@ -26,36 +28,66 @@ extern "C" int sortdir(const void * d1, const void * d2) { n = current_dir + "/" + (**((const dirent **)d2)).d_name; stat(n.to_charp(), &fstats2); - if (!(S_ISDIR(fstats1.st_mode) ^ S_ISDIR(fstats2.st_mode))) { + if (!((S_ISDIR(fstats1.st_mode) ? 1 : 0) ^ (S_ISDIR(fstats2.st_mode) ? 1 : 0))) { return alphasort(d1, d2); } else { if (S_ISDIR(fstats1.st_mode)) - return 1; - else return -1; + else + return 1; } } CODE_BEGINS + +private: + +struct couple { + String p, v; +}; + Output * Archive; +std::list<String> filelist; + +void finalize(void) { + int size; + Input * file; + for (std::list<String>::iterator i = filelist.begin(); i != filelist.end(); i++) { + cerr << "Finalize file " << *i << endl; + file = new Input(*i); + size = file->GetSize(); + Archive->write(&size, 4); + delete file; + file = new Input(*i + ".gz"); + copy(file, Archive); + delete file; + unlink((*i + ".gz").to_charp()); + } +} + void process_file(const String & filename) { char t; - int size; - cerr << "Processing file " << filename << endl; + int size, old_size; + cerr << "Processing file " << filename << "... "; Input * from = new Input(filename); Output * to = new Output(filename + ".gz"); to->SetZ(); + old_size = from->GetSize(); + copy(from, to); delete to; delete from; + filelist.push_back(filename); + from = new Input(filename + ".gz"); size = from->GetSize() + 4; + cerr << old_size << " --> " << from->GetSize() << " (" << 100 * from->GetSize() / old_size << "%)\n"; Archive->write(&size, 4); @@ -122,11 +154,15 @@ void build_archive(const String & dirname) { Archive->write(buff, 4); process_directory(dirname); + + finalize(); } +public: + virtual int startup(void) throw (GeneralException) { Archive = new Output("/tmp/bleh.paq"); - process_directory("."); + build_archive("."); return 0; } CODE_ENDS |