diff options
Diffstat (limited to 'src/commit')
-rw-r--r-- | src/commit/commit-algorithm.cpp | 35 | ||||
-rw-r--r-- | src/commit/commit-algorithm.hpp | 36 |
2 files changed, 41 insertions, 30 deletions
diff --git a/src/commit/commit-algorithm.cpp b/src/commit/commit-algorithm.cpp index ad775df..80567f0 100644 --- a/src/commit/commit-algorithm.cpp +++ b/src/commit/commit-algorithm.cpp @@ -26,7 +26,13 @@ using namespace commit; using namespace std; -////// static functions +////// static +static const char *commit_hook_dirs[3] = { + "/etc/commit/pre-hooks.d", + "/etc/commit/post-hooks.d", + NULL +}; + static void _set_node_commit_state(CfgNode& node, CommitState s, bool recursive) { @@ -742,6 +748,16 @@ _get_commit_other_node(CfgNode *cfg1, CfgNode *cfg2, const Cpath& cur_path) return cn; } +static void +_execute_hooks(CommitHook hook) +{ + string cmd = "/bin/run-parts --regex='^[a-zA-Z0-9._-]+$' -- '"; + cmd += getCommitHookDir(hook); + cmd += "'"; + // not checking return status + system(cmd.c_str()); +} + ////// class CommitData CommitData::CommitData() @@ -1043,6 +1059,15 @@ PrioNode::setSubtreeSuccess() ////// exported functions +const char * +commit::getCommitHookDir(CommitHook hook) +{ + if (hook > LAST) { + return NULL; + } + return commit_hook_dirs[hook]; +} + CfgNode * commit::getCommitTree(CfgNode *cfg1, CfgNode *cfg2, const Cpath& cur_path) { @@ -1154,6 +1179,7 @@ commit::doCommit(Cstore& cs, CfgNode& cfg1, CfgNode& cfg2) return true; } + _execute_hooks(PRE_COMMIT); set_in_commit(true); PrioNode proot(root); // proot corresponds to root @@ -1186,9 +1212,11 @@ commit::doCommit(Cstore& cs, CfgNode& cfg1, CfgNode& cfg2) pq.pop(); } bool ret = true; + const char *cst = "SUCCESS"; if (f > 0) { OUTPUT_USER("Commit failed\n"); ret = false; + cst = ((s > 0) ? "PARTIAL" : "FAILURE"); } if (!cs.commitConfig(proot)) { @@ -1204,6 +1232,11 @@ commit::doCommit(Cstore& cs, CfgNode& cfg1, CfgNode& cfg2) if (ret) { ret = cs.markSessionUnsaved(); } + + setenv("COMMIT_STATUS", cst, 1); + _execute_hooks(POST_COMMIT); + unsetenv("COMMIT_STATUS"); + return ret; } diff --git a/src/commit/commit-algorithm.hpp b/src/commit/commit-algorithm.hpp index 3bc89a7..fca04cb 100644 --- a/src/commit/commit-algorithm.hpp +++ b/src/commit/commit-algorithm.hpp @@ -50,6 +50,12 @@ enum CommitTreeTraversalOrder { POST_ORDER }; +enum CommitHook { + PRE_COMMIT, + POST_COMMIT, + LAST +}; + class CommitData { public: CommitData(); @@ -120,35 +126,6 @@ public: void setSubtreeFailure(); void setSubtreeSuccess(); -#if 0 - // XXX testing - void print(size_t lvl) { -#define INDENT for(size_t xyz = 0; xyz < lvl; xyz++) { printf(" "); }; - INDENT; - if (_node) { - printf("[%s]\n", _node->getCommitPath().to_string().c_str()); - } else { - printf("[---]\n"); - } - INDENT; printf("|cp[%s]\n", - (_cfg_parent - ? _cfg_parent->getCommitPath().to_string().c_str() - : NULL)); - if (_node) { - INDENT; printf("======\n"); - _node->rprint(lvl); - INDENT; printf("======\n"); - } -#undef INDENT - } - void rprint(size_t lvl) { - print(lvl); - for (size_t i = 0; i < numChildNodes(); i++) { - childAt(i)->rprint(lvl + 1); - } - } -#endif - private: CfgNode *_node; CfgNode *_cfg_parent; @@ -184,6 +161,7 @@ typedef std::pair<CommitState, std::tr1::shared_ptr<Cpath> > typedef std::vector<CommittedPathT> CommittedPathListT; // exported functions +const char *getCommitHookDir(CommitHook hook); CfgNode *getCommitTree(CfgNode *cfg1, CfgNode *cfg2, const Cpath& cur_path); bool isCommitPathEffective(Cstore& cs, const Cpath& pcomps, std::tr1::shared_ptr<Ctemplate> def, |