[pan2: 91/268] removed nzb resume for uploads for now ...
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2: 91/268] removed nzb resume for uploads for now ...
- Date: Mon, 2 Jan 2012 15:45:39 +0000 (UTC)
commit e34cde22b982ab3fc98911732e975d11287d56db
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date: Wed Jun 29 12:44:28 2011 +0200
removed nzb resume for uploads for now ...
pan/data/encode-cache.cc | 16 ++++++-
pan/data/encode-cache.h | 4 +-
pan/gui/post-ui.cc | 3 +-
pan/tasks/encoder.cc | 3 +-
pan/tasks/nzb.cc | 118 ++++++++++++++++++++++-----------------------
pan/tasks/task-upload.cc | 23 +++++++--
pan/tasks/task-upload.h | 8 ++-
7 files changed, 102 insertions(+), 73 deletions(-)
---
diff --git a/pan/data/encode-cache.cc b/pan/data/encode-cache.cc
index 77c1682..e29fb76 100644
--- a/pan/data/encode-cache.cc
+++ b/pan/data/encode-cache.cc
@@ -70,10 +70,11 @@ EncodeCache :: EncodeCache (const StringView& path, size_t max_megs):
while ((fname = g_dir_read_name (dir)))
{
g_snprintf (filename, sizeof(filename), "%s%c%s", _path.c_str(), G_DIR_SEPARATOR, fname);
- unlink(filename);
+ add (Quark(filename));
}
g_dir_close (dir);
}
+ debug ("loaded " << _mid_to_info.size() << " articles into cache from " << _path);
}
EncodeCache :: ~EncodeCache ()
@@ -129,10 +130,10 @@ EncodeCache :: add (const Quark& message_id)
{
MsgInfo info;
-// info._fp = fp;
info._message_id = message_id;
info._size = 0;
info._date = time(0);
+// info._fp = get_fp_from_mid(message_id);
_mid_to_info.insert (mid_to_info_t::value_type (info._message_id, info));
}
@@ -198,6 +199,16 @@ EncodeCache :: get_data(std::string& data, const Quark& where)
data = out.str();
}
+bool
+EncodeCache :: update_file (std::string& data, const Quark& where)
+{
+ FILE * fp = get_fp_from_mid(where);
+ if (!fp) return false;
+ fwrite(data.c_str(), strlen(data.c_str()), sizeof(char), fp);
+ fclose(fp);
+ return true;
+}
+
void
EncodeCache :: resize (guint64 max_bytes)
{
@@ -221,6 +232,7 @@ EncodeCache :: resize (guint64 max_bytes)
unlink (buf);
_current_bytes -= it->_size;
removed.insert (mid);
+// if (it->_fp) fclose(it->_fp);
_mid_to_info.erase (mid);
}
}
diff --git a/pan/data/encode-cache.h b/pan/data/encode-cache.h
index cd0a225..56a2d27 100644
--- a/pan/data/encode-cache.h
+++ b/pan/data/encode-cache.h
@@ -57,6 +57,7 @@ namespace pan
FILE* get_fp_from_mid(const Quark& mid);
void get_filename (char* buf, const Quark& mid) const;
+ bool update_file (std::string& data, const Quark& where);
typedef std::vector<Quark> mid_sequence_t;
@@ -91,7 +92,8 @@ namespace pan
Quark _message_id;
size_t _size;
time_t _date;
- MsgInfo(): _size(0), _date(0) {}
+ FILE * _fp;
+ MsgInfo(): _size(0), _date(0), _fp(0) {}
};
typedef std::map<Quark,MsgInfo> mid_to_info_t;
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 45c3c9b..aaf033d 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -183,8 +183,7 @@ PostUI :: on_queue_tasks_added (UploadQueue& queue, int index, int count)
void
PostUI :: on_queue_task_removed (UploadQueue&, TaskUpload& task, int index)
{
- GtkListStore *store = GTK_LIST_STORE(
- gtk_tree_view_get_model(GTK_TREE_VIEW(_filequeue_store)));
+ GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(_filequeue_store)));
const int list_index (find_task_index (store, &task));
assert (list_index == index);
diff --git a/pan/tasks/encoder.cc b/pan/tasks/encoder.cc
index 1f564a3..04c3892 100644
--- a/pan/tasks/encoder.cc
+++ b/pan/tasks/encoder.cc
@@ -117,8 +117,6 @@ Encoder :: do_work()
UUSetMsgCallback (this, uu_log);
UUSetBusyCallback (this, uu_busy_poll, 200);
-
-
batch.init(StringView(basename), needed->size(), 0);
/* build real subject line for article*/
@@ -169,6 +167,7 @@ _no_encode:
cache->finalize(it->second.message_id);
cache->get_filename(cachename, Quark(it->second.message_id));
stat (cachename, &sb);
+ it->second.cachename = cachename;
it->second.bytes = sb.st_size;
task->_all_bytes += sb.st_size;
batch.add_part(cnt, StringView(it->second.mid), sb.st_size);
diff --git a/pan/tasks/nzb.cc b/pan/tasks/nzb.cc
index 0b125e9..88a758a 100644
--- a/pan/tasks/nzb.cc
+++ b/pan/tasks/nzb.cc
@@ -48,10 +48,9 @@ namespace
quarks_t groups;
std::string text;
std::string path;
- std::vector<std::string> groups_str; // TaskUpload
- TaskUpload::needed_t needed_parts; // TaskUpload
- std::string domain; // TaskUpload
- std::string queue;
+// std::vector<std::string> groups_str; // TaskUpload
+// TaskUpload::needed_t needed_parts; // TaskUpload
+// std::string queue;
int lpf;
Article a;
PartBatch parts;
@@ -72,15 +71,15 @@ namespace
void file_clear () {
groups.clear ();
- groups_str.clear();
+// groups_str.clear();
text.clear ();
path.clear ();
a.clear ();
bytes = 0;
number = 0;
- needed_parts.clear(); // TaskUpload
- domain.clear(); // TaskUpload
- queue.clear();
+// needed_parts.clear(); // TaskUpload
+// domain.clear(); // TaskUpload
+// queue.clear();
lpf = 0;
}
};
@@ -104,17 +103,17 @@ namespace
}
}
- else if (!strcmp (element_name, "upload")) {
- mc.file_clear ();
- for (const char **k(attribute_names), **v(attribute_vals); *k; ++k, ++v) {
- if (!strcmp (*k,"author")) mc.a.author = *v;
- else if (!strcmp (*k,"subject")) mc.a.subject = *v;
- else if (!strcmp (*k,"server")) mc.server = *v;
- else if (!strcmp (*k,"domain")) mc.domain = *v;
- else if (!strcmp (*k,"queue")) mc.queue = *v;
- else if (!strcmp (*k,"lpf")) mc.lpf = atoi(*v);
- }
- }
+// else if (!strcmp (element_name, "upload")) {
+// mc.file_clear ();
+// for (const char **k(attribute_names), **v(attribute_vals); *k; ++k, ++v) {
+// if (!strcmp (*k,"author")) mc.a.author = *v;
+// else if (!strcmp (*k,"subject")) mc.a.subject = *v;
+// else if (!strcmp (*k,"server")) mc.server = *v;
+// else if (!strcmp (*k,"domain")) mc.domain = *v;
+// else if (!strcmp (*k,"queue")) mc.queue = *v;
+// else if (!strcmp (*k,"lpf")) mc.lpf = atoi(*v);
+// }
+// }
else if (!strcmp (element_name, "segment")) {
mc.bytes = 0;
@@ -125,14 +124,14 @@ namespace
}
}
- else if (!strcmp (element_name, "part")) {
- mc.bytes = 0;
- mc.number = 0;
- for (const char **k(attribute_names), **v(attribute_vals); *k; ++k, ++v) {
- if (!strcmp (*k,"bytes")) mc.bytes = strtoul (*v,0,10);
- else if (!strcmp (*k,"number")) mc.number = atoi (*v);
- }
- }
+// else if (!strcmp (element_name, "part")) {
+// mc.bytes = 0;
+// mc.number = 0;
+// for (const char **k(attribute_names), **v(attribute_vals); *k; ++k, ++v) {
+// if (!strcmp (*k,"bytes")) mc.bytes = strtoul (*v,0,10);
+// else if (!strcmp (*k,"number")) mc.number = atoi (*v);
+// }
+// }
}
// Called for close tags </foo>
@@ -146,7 +145,7 @@ namespace
if (!strcmp(element_name, "group"))
{
mc.groups.insert (Quark (mc.text));
- mc.groups_str.push_back(mc.text);
+// mc.groups_str.push_back(mc.text);
}
else if (!strcmp(element_name, "segment") && mc.number && !mc.text.empty()) {
@@ -158,14 +157,14 @@ namespace
mc.parts.add_part (mc.number, mid, mc.bytes);
}
- else if (!strcmp(element_name, "part") && mc.number && !mc.text.empty()) {
- mc.a.message_id = mc.text;
- TaskUpload::Needed n;
- n.partno = mc.number;
- n.message_id = mc.text;
- n.bytes = mc.bytes;
- mc.needed_parts.insert(std::pair<int, TaskUpload::Needed>(mc.number,n));
- }
+// else if (!strcmp(element_name, "part") && mc.number && !mc.text.empty()) {
+// mc.a.message_id = mc.text;
+// TaskUpload::Needed n;
+// n.partno = mc.number;
+// n.message_id = mc.text;
+// n.bytes = mc.bytes;
+// mc.needed_parts.insert(std::pair<int, TaskUpload::Needed>(mc.number,n));
+// }
else if (!strcmp(element_name,"path"))
mc.path = mc.text;
@@ -186,22 +185,25 @@ namespace
mc.tasks.push_back (new TaskArticle (mc.ranks, mc.gs, mc.a, mc.cache, mc.read, 0, TaskArticle::DECODE, p));
}
- else if (!strcmp (element_name, "upload"))
- {
- debug("adding taskupload from nzb.\n");
- foreach_const (quarks_t, mc.groups, git)
- mc.a.xref.insert (mc.server, *git, 0);
- ///TODO export/import missing values to/from nzb
- TaskUpload::UploadInfo format;
-// format.domain = mc.domain;
- format.comment1 = true;
- format.lpf = mc.lpf;
-
-///TODO implement gmimemessage here
+// else if (!strcmp (element_name, "upload"))
+// {
+// debug("adding taskupload from nzb.\n");
+// foreach_const (quarks_t, mc.groups, git)
+// mc.a.xref.insert (mc.server, *git, 0);
+// TaskUpload::UploadInfo format;
+// format.comment1 = true;
+// format.lpf = mc.lpf;
+//
// TaskUpload* tmp = new TaskUpload (mc.path, mc.server, mc.encode_cache,mc.a,
-// format, mc.needed_parts, 0, TaskUpload::YENC);
+// format, 0, 0, TaskUpload::YENC);
+//
+// /* build needed parts */
+// foreach (TaskUpload::needed_t, mc.needed_parts, it)
+// tmp->needed().insert(*it);
+// tmp->build_needed_tasks();
+//
// mc.tasks.push_back (tmp);
- }
+// }
}
void text (GMarkupParseContext *context UNUSED,
@@ -359,7 +361,6 @@ NZB :: nzb_to_xml (std::ostream & out,
//
// const Article& a (task->get_article());
//
-// //info: author, subject, load path, parts to encode / post
// out << indent(depth)
// << "<upload" << " author=\"";
// escaped (out, task->_author);
@@ -368,23 +369,21 @@ NZB :: nzb_to_xml (std::ostream & out,
// out << "\" server=\"";
// escaped (out, task->_server.to_string());
//
-// ///TODO
-//// out << "\" queue=\"";
-//// escaped (out, task->_save_file);
+// ///TODO _save_file
// out << "\" lpf=\"";
// char buf[256];
// g_snprintf(buf,sizeof(buf),"%d",task->_lpf);
// escaped (out, buf);
+// out <<"\">\n";
// ++depth;
// out << indent(depth)
// << "<path>" << task->_filename << "</path>\n";
// out << indent(depth) << "<groups>\n";
//
-// ///TODO
-//// ++depth;
-//// foreach_const (quarks_t, task->_groups, git)
-//// out << indent(depth) << "<group>" << *git << "</group>\n";
-//// --depth;
+// ++depth;
+// foreach_const (Xref, task->_article.xref, xit)
+// out << indent(depth) << "<group>" << xit->group << "</group>\n";
+// --depth;
//
// out << indent(--depth) << "</groups>\n";
// out << indent(depth) << "<parts>\n";
@@ -403,7 +402,6 @@ NZB :: nzb_to_xml (std::ostream & out,
// out << indent(depth) << "</parts>\n";
// out << indent(depth) << "</upload>\n";
// }
-// }
}
out << indent(--depth) << "</nzb>\n";
return out;
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index 7432ec7..508d2c1 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -121,6 +121,8 @@ TaskUpload :: build_needed_tasks()
}
+static bool inited(false);
+
void
TaskUpload :: update_work (NNTP* checkin_pending)
{
@@ -134,7 +136,7 @@ TaskUpload :: update_work (NNTP* checkin_pending)
}
/* only need encode if mode is NOT plain */
- if (!_encoder && !_encoder_has_run)
+ if (!_encoder && !_encoder_has_run && _msg)
{
_state.set_need_encoder();
}
@@ -142,8 +144,22 @@ TaskUpload :: update_work (NNTP* checkin_pending)
{
_state.set_working();
}
- else if (_encoder_has_run && !_needed.empty())
+ else if ((_encoder_has_run && !_needed.empty()) || !_msg)
{
+ if (_msg && !inited)
+ {
+
+ std::string data;
+ foreach (needed_t, _needed, nit)
+ {
+ Needed& n (nit->second);
+ _cache.get_data(data,n.message_id.c_str());
+ prepend_headers(_msg,&n, data);
+ /* update cache file */
+ _cache.update_file (data,n.message_id.c_str());
+ }
+ inited = true;
+ }
_state.set_need_nntp(_server);
}
else if (_needed.empty())
@@ -204,8 +220,7 @@ TaskUpload :: use_nntp (NNTP * nntp)
set_status_va (_("Uploading %s - Part %d of %d"), _basename.c_str(), needed->partno, _total_parts);
std::string data;
- _cache.get_data(data,needed->message_id.c_str());
- prepend_headers(_msg,needed, data);
+ _cache.get_data(data,needed->message_id.c_str());
nntp->post(StringView(data), this);
update_work ();
}
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index a8cb278..cf7c7b3 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -73,6 +73,7 @@ namespace pan
NNTP* nntp;
std::string message_id;
std::string mid; // for rng
+ std::string cachename;
Xref xref;
bool encoded;
Needed (): nntp(0), bytes(0) , partno(1), encoded(false) {}
@@ -155,6 +156,7 @@ namespace pan
friend class Encoder;
friend class PostUI;
friend class NZB;
+ friend class MyContext;
Encoder * _encoder;
bool _encoder_has_run;
std::string _filename;
@@ -172,12 +174,14 @@ namespace pan
Article::mid_sequence_t _mids;
int _queue_pos;
int _lpf;
-
- private:
needed_t _needed;
+
void update_work (NNTP * checkin_pending = 0);
+
+ public:
void build_needed_tasks();
+ private:
GMimeMessage * _msg;
void prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::string& d);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]