#include <zypp/SourceManager.h>
#include <zypp/SourceFactory.h>
+#include "zypp/ZYppCallbacks.h"
#include "zypp/NVRAD.h"
#include "zypp/ResPool.h"
#include "zypp/ResFilters.h"
///////////////////////////////////////////////////////////////////
+struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
+{
+ virtual void start( const Resolvable::constPtr & script_r,
+ const Pathname & path_r,
+ Task task_r )
+ {
+ SEC << __FUNCTION__ << endl
+ << " " << script_r << endl
+ << " " << path_r << endl
+ << " " << task_r << endl;
+ }
+
+ virtual bool progress( Notify notify_r, const std::string & text_r )
+ {
+ SEC << __FUNCTION__ << endl
+ << " " << notify_r << endl
+ << " " << text_r << endl;
+ return true;
+ }
+
+ virtual void problem( const std::string & description_r )
+ {
+ SEC << __FUNCTION__ << endl
+ << " " << description_r << endl;
+ }
+
+ virtual void finish()
+ {
+ SEC << __FUNCTION__ << endl;
+ }
+
+};
+
+///////////////////////////////////////////////////////////////////
+
namespace container
{
template<class _Tp>
{
//zypp::base::LogControl::instance().logfile( "log.restrict" );
INT << "===[START]==========================================" << endl;
+
+ ConvertDbReceive r;
+ r.connect();
+
ResPool pool( getZYpp()->pool() );
if ( 1 )
}
if ( 1 ) {
- zypp::base::LogControl::TmpLineWriter shutUp;
+ //zypp::base::LogControl::TmpLineWriter shutUp;
//SourceManager::sourceManager()->restore( sysRoot );
if ( 1 || SourceManager::sourceManager()->allSources().empty() )
{
- //Source_Ref src1( createSource( "dir:////schnell/CD-ARCHIVE/10.1/SUSE-Linux-10.1-RC5-FTP/CD1" ) );
- Source_Ref src1( createSource( "ftp://schnell/CD-ARCHIVE/10.1/SUSE-Linux-10.1-RC5-FTP/CD1" ) );
+ Source_Ref src1( createSource( "dir:/Local/script" ) );
SourceManager::sourceManager()->addSource( src1 );
//SourceManager::sourceManager()->store( sysRoot, true );
}
MIL << *SourceManager::sourceManager() << endl;
MIL << pool << endl;
-
+ //vdumpPoolStats( SEC, pool.begin(), pool.end() ) << endl;
if ( 1 )
{
#define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
- selt( Package, bash );
+ selt( Script, fetchmsttfonts.sh-patch-fetchmsttfonts.sh-2 );
#undef selt
}
/** \file zypp/target/TargetImpl.cc
*
*/
-#include <sys/types.h>
-#include <sys/stat.h>
+//#include <sys/types.h>
+//#include <sys/stat.h>
#include <iostream>
+#include <sstream>
#include <string>
#include <list>
#include <set>
namespace target
{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+ void ExecuteScriptHelper( Script::constPtr script_r, bool do_r )
+ {
+ MIL << "Execute script " << script_r << endl;
+ if ( ! script_r )
+ {
+ INT << "NULL Script passed." << endl;
+ return;
+ }
+
+ Pathname path;
+ if ( do_r )
+ {
+ path = script_r->do_script();
+ }
+ else
+ {
+ if ( script_r->undo_available() )
+ {
+ path = script_r->undo_script();
+ }
+ else
+ {
+ DBG << "No undo script for " << script_r << endl;
+ return; // success
+ }
+ }
+
+ // Go...
+ callback::SendReport<ScriptResolvableReport> report;
+ report->start( script_r, path,
+ (do_r ? ScriptResolvableReport::DO
+ : ScriptResolvableReport::UNDO ) );
+
+ PathInfo pi( path );
+ if ( ! pi.isFile() )
+ {
+ std::ostringstream err;
+ err << "Script is not a file: " << pi.fileType() << " " << path;
+ report->problem( err.str() );
+ ZYPP_THROW(Exception(err.str()));
+ }
+
+ filesystem::chmod( path, S_IRUSR|S_IXUSR ); // "r-x------"
+ ExternalProgram prog( path.asString(), ExternalProgram::Stderr_To_Stdout, false, -1, true );
+ for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
+ {
+ report->progress( ScriptResolvableReport::OUTPUT, output );
+ }
+
+ int exitCode = prog.close();
+ if ( exitCode != 0 )
+ {
+ std::ostringstream err;
+ err << "Script failed with exit code " << exitCode;
+ report->problem( err.str() );
+ ZYPP_THROW(Exception(err.str()));
+ }
+
+ report->finish();
+ return;
+ }
+
+ inline void ExecuteDoScript( const Script::constPtr & script_r )
+ {
+ ExecuteScriptHelper( script_r, true );
+ }
+
+ inline void ExecuteUndoScript( const Script::constPtr & script_r )
+ {
+ ExecuteScriptHelper( script_r, false );
+ }
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
+
+
/** Helper for PackageProvider queries during commit. */
struct QueryInstalledEditionHelper
{
rpm::RpmDb & _rpmdb;
};
-
IMPL_PTR_TYPE(TargetImpl);
TargetImpl_Ptr TargetImpl::_nullimpl;
}
else if (isKind<Script>(it->resolvable()))
{
- Script::constPtr s = dynamic_pointer_cast<const Script>(it->resolvable());
- Pathname p = s->do_script();
- if (p != "" && p != "/")
- {
- chmod( p.asString().c_str(), S_IRUSR|S_IXUSR ); // "r-x------"
- ExternalProgram* prog = new ExternalProgram(p.asString(), ExternalProgram::Discard_Stderr, false, -1, true);
- if (! prog)
- ZYPP_THROW(Exception("Cannot run the script"));
- int retval = prog->close();
- delete prog;
- if (retval != 0)
- ZYPP_THROW(Exception("Exit code of script is non-zero"));
- }
- else
- {
- ERR << "Do script not defined" << endl;
- }
+ ExecuteDoScript( asKind<Script>(it->resolvable()) );
}
else if (!isKind<Atom>(it->resolvable())) // atoms are re-created from the patch data, no need to save them
{
}
else if (isKind<Script>(it->resolvable()))
{
- Script::constPtr s = dynamic_pointer_cast<const Script>(it->resolvable());
- Pathname p = s->undo_script();
- if (! s->undo_available())
- {
- DBG << "Undo script not available" << endl;
- }
- if (p != "" && p != "/")
- {
- ExternalProgram* prog = new ExternalProgram(p.asString(), ExternalProgram::Discard_Stderr, false, -1, true);
- if (! prog)
- ZYPP_THROW(Exception("Cannot run the script"));
- int retval = prog->close();
- delete prog;
- if (retval != 0)
- ZYPP_THROW(Exception("Exit code of script is non-zero"));
- }
- else
- {
- ERR << "Undo script not defined" << endl;
- }
+ ExecuteUndoScript( asKind<Script>(it->resolvable()) );
}
else
{