[pan2: 30/68] Allow newsrc paths relative to PAN_HOME.
- From: Petr Kovář <pmkovar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2: 30/68] Allow newsrc paths relative to PAN_HOME.
- Date: Tue, 8 Feb 2011 23:00:33 +0000 (UTC)
commit 7445405fb500ffd4ec0c85b1995c80faad5175a1
Author: K. Haley <haleykd users sf net>
Date: Wed Jul 21 17:57:39 2010 -0600
Allow newsrc paths relative to PAN_HOME.
The newsrc file paths inservers.xml can now be either absolute
or relative to the PAN_HOME directory. Also new server entries
will use relative paths.
pan/data-impl/groups.cc | 18 ++++++++++++++++--
pan/data-impl/server.cc | 3 ++-
2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/pan/data-impl/groups.cc b/pan/data-impl/groups.cc
index 73941a3..b0a597c 100644
--- a/pan/data-impl/groups.cc
+++ b/pan/data-impl/groups.cc
@@ -155,6 +155,20 @@ DataImpl :: load_newsrc (const Quark & server,
}
}
+namespace {
+ inline std::string newsrc_fn(const std::string &base)
+ {
+ const char *fn = base.c_str();
+ if (g_path_is_absolute(fn))
+ return base;
+ const char *ph = file::get_pan_home().c_str();
+ char *temp = g_build_filename(ph, fn, 0);
+ std::string out(temp);
+ g_free(temp);
+ return out;
+ }
+}
+
void
DataImpl :: load_newsrc_files (const DataIO& data_io)
{
@@ -166,7 +180,7 @@ DataImpl :: load_newsrc_files (const DataIO& data_io)
foreach_const (servers_t, _servers, sit) {
const Quark key (sit->first);
- const std::string filename (sit->second.newsrc_filename);
+ const std::string filename = newsrc_fn (sit->second.newsrc_filename);
if (file::file_exists (filename.c_str())) {
LineReader * in (data_io.read_file (filename));
load_newsrc (key, in, s, u);
@@ -210,7 +224,7 @@ DataImpl :: save_newsrc_files (DataIO& data_io) const
const Quark& server (sit->first);
// write this server's newsrc
- const std::string& filename (sit->second.newsrc_filename);
+ const std::string filename = newsrc_fn (sit->second.newsrc_filename);
std::ostream& out (*data_io.write_file (filename));
std::string newsrc_string;
alpha_groups_t::const_iterator sub_it (_subscribed.begin());
diff --git a/pan/data-impl/server.cc b/pan/data-impl/server.cc
index 0afc4ad..b927fb9 100644
--- a/pan/data-impl/server.cc
+++ b/pan/data-impl/server.cc
@@ -72,7 +72,8 @@ DataImpl :: add_new_server ()
// add it to the _servers map and give it a default filename
std::ostringstream o;
- o << file::get_pan_home() << G_DIR_SEPARATOR << "newsrc-" << new_server;
+ //o << file::get_pan_home() << G_DIR_SEPARATOR << "newsrc-" << new_server;
+ o << "newsrc-" << new_server;
_servers[new_server].newsrc_filename = o.str ();
return new_server;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]