[Debtags-commits] [svn] r2055 - in daemon: . src
Enrico Zini
enrico at alioth.debian.org
Wed Nov 8 20:38:46 CET 2006
Author: enrico
Date: Wed Nov 8 20:38:46 2006
New Revision: 2055
Modified:
daemon/ (props changed)
daemon/src/debtagsd.cpp
Log:
r3606 at viaza: enrico | 2006-11-08 19:36:58 +0000
Better handling of errors in patch handling
Modified: daemon/src/debtagsd.cpp
==============================================================================
--- daemon/src/debtagsd.cpp (original)
+++ daemon/src/debtagsd.cpp Wed Nov 8 20:38:46 2006
@@ -442,72 +442,77 @@
}
else if (cmd == "PATCH")
{
- // Read the patch in `buf`
- string buf;
- while (true)
- {
- string line = conn.readline();
- cfg.log() << "Patch line: " << line << endl;
-
- // End with an empty line
- if (line.empty()) break;
-
- buf += line;
- buf += "\n";
- }
- // conn.discardRemainingInput();
- cfg.log() << "Got the patch" << endl;
-
- // Parse the patch
- tagcoll::input::String in(buf);
- tagcoll::PatchList<std::string, std::string> patches =
- tagcoll::textformat::parsePatch(in);
-
- // Validate the patch, removing all non existing tags
- for (tagcoll::PatchList<std::string, std::string>::iterator i = patches.begin();
- i != patches.end(); ++i)
- {
- // We just need to remove nonexisting tags from added: they
- // are harmless in removed
- vector<string> nonexisting;
- for (set<string>::const_iterator j = i->second.added.begin();
- j != i->second.added.end(); ++j)
- if (!tags.has(*j))
- nonexisting.push_back(*j);
- for (vector<string>::const_iterator j = nonexisting.begin();
- j != nonexisting.end(); ++j)
- i->second.added.erase(*j);
+ try {
+ // Read the patch in `buf`
+ string buf;
+ while (true)
+ {
+ string line = conn.readline();
+ cfg.log() << "Patch line: " << line << endl;
+
+ // End with an empty line
+ if (line.empty()) break;
+
+ buf += line;
+ buf += "\n";
+ }
+ // conn.discardRemainingInput();
+ cfg.log() << "Got the patch" << endl;
+
+ // Parse the patch
+ tagcoll::input::String in(buf);
+ tagcoll::PatchList<std::string, std::string> patches =
+ tagcoll::textformat::parsePatch(in);
+
+ // Validate the patch, removing all non existing tags
+ for (tagcoll::PatchList<std::string, std::string>::iterator i = patches.begin();
+ i != patches.end(); ++i)
+ {
+ // We just need to remove nonexisting tags from added: they
+ // are harmless in removed
+ vector<string> nonexisting;
+ for (set<string>::const_iterator j = i->second.added.begin();
+ j != i->second.added.end(); ++j)
+ if (!tags.has(*j))
+ nonexisting.push_back(*j);
+ for (vector<string>::const_iterator j = nonexisting.begin();
+ j != nonexisting.end(); ++j)
+ i->second.added.erase(*j);
+ }
+
+ cfg.log() << "XX validated" << endl;
+
+ // Apply the patch
+ coll.applyChange(patches);
+
+ cfg.log() << "XX applied" << endl;
+
+ // Save the patch on a file
+
+ // Build the file name
+ time_t now = time(NULL);
+ struct tm t;
+ if (localtime_r(&now, &t) == NULL)
+ throw wibble::exception::System("getting local time information");
+ char file[40];
+ snprintf(file, 40, "%04d%02d%02d-%02d%02d%02d-%d-%d.patch",
+ t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
+ getpid(), ++seq);
+ std::string fname = cfg.patchdir + "/" + file;
+
+ cfg.log() << "XX saving in " << fname << endl;
+
+ // Write the patch
+ ofstream out(fname.c_str());
+ out << buf;
+ out.close();
+
+ cfg.log() << "XX saved in " << fname << endl;
+ conn.write("200 OK\n");
+ } catch (std::exception& e) {
+ cfg.log() << e.what() << endl;
+ conn.write(string("500 Internal server error: ") + e.what() + "\n");
}
-
- cfg.log() << "XX validated" << endl;
-
- // Apply the patch
- coll.applyChange(patches);
-
- cfg.log() << "XX applied" << endl;
-
- // Save the patch on a file
-
- // Build the file name
- time_t now = time(NULL);
- struct tm t;
- if (localtime_r(&now, &t) == NULL)
- throw wibble::exception::System("getting local time information");
- char file[40];
- snprintf(file, 40, "%04d%02d%02d-%02d%02d%02d-%d-%d.patch",
- t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
- getpid(), ++seq);
- std::string fname = cfg.patchdir + "/" + file;
-
- cfg.log() << "XX saving in " << fname << endl;
-
- // Write the patch
- ofstream out(fname.c_str());
- out << buf;
- out.close();
-
- cfg.log() << "XX saved in " << fname << endl;
- conn.write("200 OK\n");
}
else
conn.write("Command not recognized: " + cmd + "\n");
More information about the Debtags-commits
mailing list