summaryrefslogtreecommitdiff
path: root/src/cstore/unionfs/cstore-unionfs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cstore/unionfs/cstore-unionfs.cpp')
-rw-r--r--src/cstore/unionfs/cstore-unionfs.cpp101
1 files changed, 46 insertions, 55 deletions
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp
index 7f14483..eebabfe 100644
--- a/src/cstore/unionfs/cstore-unionfs.cpp
+++ b/src/cstore/unionfs/cstore-unionfs.cpp
@@ -17,7 +17,6 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <map>
#include <fstream>
#include <sstream>
@@ -63,8 +62,8 @@ const string UnionfsCstore::C_DEF_NAME = "node.def";
////// static
-static map<char, string> _fs_escape_chars;
-static map<string, char> _fs_unescape_chars;
+static Cstore::MapT<char, string> _fs_escape_chars;
+static Cstore::MapT<string, char> _fs_unescape_chars;
static void
_init_fs_escape_chars()
{
@@ -80,7 +79,7 @@ _init_fs_escape_chars()
static string
_escape_char(char c)
{
- map<char, string>::iterator p = _fs_escape_chars.find(c);
+ Cstore::MapT<char, string>::iterator p = _fs_escape_chars.find(c);
if (p != _fs_escape_chars.end()) {
return _fs_escape_chars[c];
} else {
@@ -88,12 +87,13 @@ _escape_char(char c)
}
}
-static map<string, string> _escape_path_name_cache;
+static Cstore::MapT<string, string> _escape_path_name_cache;
static string
_escape_path_name(const string& path)
{
- map<string, string>::iterator p = _escape_path_name_cache.find(path);
+ Cstore::MapT<string, string>::iterator p
+ = _escape_path_name_cache.find(path);
if (p != _escape_path_name_cache.end()) {
// found escaped string in cache. just return it.
return _escape_path_name_cache[path];
@@ -110,12 +110,13 @@ _escape_path_name(const string& path)
return npath;
}
-static map<string, string> _unescape_path_name_cache;
+static Cstore::MapT<string, string> _unescape_path_name_cache;
static string
_unescape_path_name(const string& path)
{
- map<string, string>::iterator p = _unescape_path_name_cache.find(path);
+ Cstore::MapT<string, string>::iterator p
+ = _unescape_path_name_cache.find(path);
if (p != _unescape_path_name_cache.end()) {
// found unescaped string in cache. just return it.
return _unescape_path_name_cache[path];
@@ -129,7 +130,7 @@ _unescape_path_name(const string& path)
break;
}
string s = path.substr(i, 3);
- map<string, char>::iterator p = _fs_unescape_chars.find(s);
+ Cstore::MapT<string, char>::iterator p = _fs_unescape_chars.find(s);
if (p != _fs_unescape_chars.end()) {
char c = _fs_unescape_chars[s];
if (path.size() == 3 && c == -1) {
@@ -749,6 +750,38 @@ UnionfsCstore::unmark_deactivated_descendants()
return ret;
}
+// mark current work path and all ancestors as "changed"
+bool
+UnionfsCstore::mark_changed_with_ancestors()
+{
+ b_fs::path opath = mutable_cfg_path; // use a copy
+ bool done = false;
+ while (!done) {
+ b_fs::path marker = work_root;
+ if (opath.has_parent_path()) {
+ marker /= opath;
+ pop_path(opath);
+ } else {
+ done = true;
+ }
+ if (!b_fs_exists(marker) || !b_fs_is_directory(marker)) {
+ // don't do anything if the node is not there
+ continue;
+ }
+ marker /= C_MARKER_CHANGED;
+ if (b_fs_exists(marker)) {
+ // reached a node already marked => done
+ break;
+ }
+ if (!create_file(marker.file_string())) {
+ output_internal("failed to mark changed [%s]\n",
+ marker.file_string().c_str());
+ return false;
+ }
+ }
+ return true;
+}
+
/* remove all "changed" markers under the current work path. this is used,
* e.g., at the end of "commit" to reset a subtree.
*/
@@ -777,39 +810,6 @@ UnionfsCstore::unmark_changed_with_descendants()
return true;
}
-bool
-UnionfsCstore::mark_changed()
-{
- if (!mutable_cfg_path.has_parent_path()) {
- /* at root, mark changed. root marker is needed by the original
- * implementation as an indication of whether the whole config
- * has changed.
- */
- b_fs::path marker = get_work_path() / C_MARKER_CHANGED;
- if (b_fs_exists(marker)) {
- // already marked. treat as success.
- return true;
- }
- if (!create_file(marker.file_string())) {
- output_internal("failed to mark changed [%s]\n",
- get_work_path().file_string().c_str());
- return false;
- }
- return true;
- }
-
- /* XXX not at root => nop for now.
- * we should be marking changed here. however, as commit is still
- * using its own unionfs implementation, it will not understand the
- * markers and therefore will not perform the necessary cleanup when
- * it's done.
- *
- * for now, don't mark anything besides root. the query function
- * will use unionfs-specific implementation (changes-only dir).
- */
- return true;
-}
-
// remove the comment at the current work path
bool
UnionfsCstore::remove_comment()
@@ -880,21 +880,12 @@ UnionfsCstore::get_comment(string& comment, bool active_cfg)
return read_whole_file(cfile, comment);
}
+// whether current work path is "changed"
bool
-UnionfsCstore::marked_changed()
+UnionfsCstore::cfg_node_changed()
{
- /* this function is only called by cfgPathChanged() in base class.
- *
- * XXX currently just use the changes_only dir for this query.
- * see explanation in mark_changed().
- *
- * this implementation relies on the fact that cfgPathChanged()
- * includes deleted/added nodes (including deactivated/activated
- * nodes since it's NOT deactivate-aware). if that is not the case,
- * result will be different between deleted nodes (NOT IN
- * changes_only) and deactivated nodes (IN changes_only).
- */
- return b_fs_exists(get_change_path());
+ b_fs::path marker = get_work_path() / C_MARKER_CHANGED;
+ return b_fs_exists(marker);
}
/* XXX currently "committed marking" is done inside commit.