YUMScriptImpl.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include "zypp/source/yum/YUMScriptImpl.h"
00013 #include "zypp/Arch.h"
00014 #include "zypp/Edition.h"
00015 #include "zypp/base/Gettext.h"
00016 #include "zypp/ZYppFactory.h"
00017 
00018 #include "zypp/source/yum/YUMSourceImpl.h"
00019 
00020 #include <fstream>
00021 
00022 
00023 using namespace std;
00024 using namespace zypp::detail;
00025 
00027 namespace zypp
00028 { 
00029 
00030   namespace source
00031   { 
00032     namespace yum
00033     {
00034 
00036       //
00037       //        CLASS NAME : YUMScriptImpl
00038       //
00040 
00043       YUMScriptImpl::YUMScriptImpl(
00044         Source_Ref source_r,
00045         const zypp::parser::yum::YUMPatchScript & parsed
00046       )
00047       : _do_script(parsed.do_script)
00048       , _undo_script(parsed.undo_script)
00049       , _do_location(parsed.do_location)
00050       , _undo_location(parsed.undo_location)
00051       , _do_media(1)
00052       , _undo_media(1)
00053       , _do_checksum(parsed.do_checksum_type, parsed.do_checksum)
00054       , _undo_checksum(parsed.undo_checksum_type, parsed.undo_checksum)
00055       , _source(source_r)
00056       {
00057         unsigned do_media = strtol(parsed.do_media.c_str(), 0, 10);
00058         if (do_media > 0)
00059           _do_media = do_media;
00060         unsigned undo_media = strtol(parsed.undo_media.c_str(), 0, 10);
00061         if (undo_media > 0)
00062           _undo_media = undo_media;
00063       }
00064 
00065       Pathname YUMScriptImpl::do_script() const {
00066         if (_do_script != "")
00067         {
00068           if ( !_tmp_do_script )
00069             _tmp_do_script.reset(new filesystem::TmpDir(getZYpp()->tmpPath()));
00070 
00071           Pathname pth = _tmp_do_script->path();
00072           // FIXME check success
00073           ofstream st(pth.asString().c_str());
00074           st << _do_script << endl;
00075           return pth;
00076         }
00077         else if (_do_location != "" && _do_location != "/")
00078         {
00079           Pathname script = source().provideFile(_do_location, _do_media);
00080           if (! YUMSourceImpl::checkCheckSum(script, _do_checksum.type(), _do_checksum.checksum()))
00081           {
00082             ZYPP_THROW(Exception(N_("Failed check for the script file check sum")));
00083           }
00084           return script;
00085         }
00086         else
00087         {
00088           return Pathname();
00089         }
00090       }
00092      Pathname YUMScriptImpl::undo_script() const
00093      {
00094         if (_undo_script != "")
00095         {
00096           if ( !_tmp_undo_script )
00097             _tmp_undo_script.reset(new filesystem::TmpDir(getZYpp()->tmpPath()));
00098 
00099           Pathname pth = _tmp_undo_script->path();
00100           // FIXME check success
00101           ofstream st(pth.asString().c_str());
00102           st << _undo_script << endl;
00103           return pth;
00104         }
00105         else if (_undo_location != "" && _undo_location != "/")
00106         {
00107           Pathname script = source().provideFile(_undo_location, _undo_media);
00108           if (! YUMSourceImpl::checkCheckSum(script, _undo_checksum.type(), _undo_checksum.checksum()))
00109           {
00110             ZYPP_THROW(Exception(N_("Failed check for the script file check sum")));
00111           }
00112           return script;
00113         }
00114         else return Pathname();
00115       }
00117       bool YUMScriptImpl::undo_available() const {
00118         return _undo_script != ""
00119           || (_undo_location != "" && _undo_location != "/");
00120       }
00121 
00122       Source_Ref YUMScriptImpl::source() const
00123       { return _source; }
00124 
00125 
00126 
00127     } // namespace yum
00129   } // namespace source
00132 } // namespace zypp

Generated on Mon Jul 17 22:25:16 2006 for zypp by  doxygen 1.4.6