From: Arvin Schnell Date: Wed, 5 Feb 2014 10:43:29 +0000 (+0100) Subject: - cleanup X-Git-Tag: v0.2.1^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F42%2Fhead;p=thirdparty%2Fsnapper.git - cleanup --- diff --git a/snapper/Lvm.cc b/snapper/Lvm.cc index 3a0af36d..05288882 100644 --- a/snapper/Lvm.cc +++ b/snapper/Lvm.cc @@ -370,7 +370,7 @@ namespace snapper { SystemCmd cmd(string(LVMBIN " version")); - if (cmd.retcode() != 0) + if (cmd.retcode() != 0 || cmd.stdout().empty()) { y2war("Couldn't get LVM version info"); } @@ -378,7 +378,7 @@ namespace snapper { Regex rx(".*LVM[[:space:]]+version:[[:space:]]+([0-9]+)\\.([0-9]+)\\.([0-9]+).*$"); - if (!rx.match(cmd.getLine(0))) + if (!rx.match(cmd.stdout().front())) { y2war("LVM version format didn't match"); } diff --git a/snapper/LvmCache.cc b/snapper/LvmCache.cc index 50e1db00..fb9042ae 100644 --- a/snapper/LvmCache.cc +++ b/snapper/LvmCache.cc @@ -142,15 +142,14 @@ namespace snapper boost::unique_lock unique_lock(lv_mutex); SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype " + quote(vg->get_vg_name() + "/" + lv_name)); - - if (cmd.retcode() != 0 || cmd.numLines() < 1) + if (cmd.retcode() != 0 || cmd.stdout().empty()) { y2err("lvm cache: failed to get info about " << vg->get_vg_name() << "/" << lv_name); throw LvmCacheException(); } vector args; - const string tmp = boost::trim_copy(cmd.getLine(0)); + const string tmp = boost::trim_copy(cmd.stdout().front()); boost::split(args, tmp, boost::is_any_of(" \t\n"), boost::token_compress_on); if (args.size() < 1) throw LvmCacheException(); @@ -282,14 +281,14 @@ namespace snapper else { SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype " + quote(vg_name + "/" + lv_name)); - if (cmd.retcode() != 0 || cmd.numLines() < 1) + if (cmd.retcode() != 0 || cmd.stdout().empty()) { y2err("lvm cache: failed to get info about " << vg_name << "/" << lv_name); throw LvmCacheException(); } vector args; - const string tmp = boost::trim_copy(cmd.getLine(0)); + const string tmp = boost::trim_copy(cmd.stdout().front()); boost::split(args, tmp, boost::is_any_of(" \t\n"), boost::token_compress_on); if (args.size() < 1) throw LvmCacheException(); diff --git a/snapper/SystemCmd.cc b/snapper/SystemCmd.cc index 4a501114..83612bb9 100644 --- a/snapper/SystemCmd.cc +++ b/snapper/SystemCmd.cc @@ -410,43 +410,6 @@ SystemCmd::getLine( unsigned Nr_iv, bool Sel_bv, OutputStream Idx_iv ) const } -int -SystemCmd::select( const string& Pat_Cv, OutputStream Idx_iv ) - { - if( Idx_iv > 1 ) - { - y2err("invalid index " << Idx_iv); - } - string Search_Ci( Pat_Cv ); - bool BeginOfLine_bi = Search_Ci.length()>0 && Search_Ci[0]=='^'; - if( BeginOfLine_bi ) - { - Search_Ci.erase( 0, 1 ); - } - SelLines_aC[Idx_iv].resize(0); - int Size_ii = 0; - int End_ii = Lines_aC[Idx_iv].size(); - for( int I_ii=0; I_ii0 && BeginOfLine_bi ) - { - Pos_ii = string::npos; - } - if (Pos_ii != string::npos) - { - SelLines_aC[Idx_iv].resize( Size_ii+1 ); - SelLines_aC[Idx_iv][Size_ii] = &Lines_aC[Idx_iv][I_ii]; - y2deb("Select Added Line " << Size_ii << " \"" << *SelLines_aC[Idx_iv][Size_ii] << "\""); - Size_ii++; - } - } - - y2mil("Pid:" << Pid_i << " Idx:" << Idx_iv << " Pattern:\"" << Pat_Cv << "\" Lines:" << Size_ii); - return Size_ii; - } - - void SystemCmd::invalidate() { diff --git a/snapper/SystemCmd.h b/snapper/SystemCmd.h index 29a48264..0b812ff3 100644 --- a/snapper/SystemCmd.h +++ b/snapper/SystemCmd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2004-2012] Novell, Inc. + * Copyright (c) [2004-2014] Novell, Inc. * * All Rights Reserved. * @@ -48,19 +48,24 @@ namespace snapper virtual ~SystemCmd(); + protected: + int execute(const string& Command_Cv); int executeBackground(const string& Command_Cv); int executeRestricted(const string& Command_Cv, unsigned long MaxTimeSec, unsigned long MaxLineOut, bool& ExceedTime, bool& ExceedLines); + public: + const vector& stdout() const { return Lines_aC[IDX_STDOUT]; } const vector& stderr() const { return Lines_aC[IDX_STDERR]; } string cmd() const { return lastCmd; } int retcode() const { return Ret_i; } - int select(const string& Reg_Cv, OutputStream Idx_ii = IDX_STDOUT); + protected: + unsigned numLines(bool Selected_bv = false, OutputStream Idx_ii = IDX_STDOUT) const; string getLine(unsigned Num_iv, bool Selected_bv = false, OutputStream Idx_ii = IDX_STDOUT) const; @@ -68,6 +73,8 @@ namespace snapper static void setTestmode(bool testmode = true); + public: + /** * Quotes and protects a single string for shell execution. */