create a tmp file when reading the scripts from the store, from the embeded xml
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 27 Mar 2006 16:33:37 +0000 (16:33 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 27 Mar 2006 16:33:37 +0000 (16:33 +0000)
zypp/target/store/XMLFilesBackend.cc
zypp/target/store/serialize.cc
zypp/target/store/xml/XMLScriptImpl.cc
zypp/target/store/xml/XMLScriptImpl.h

index 9e4ea90..fee121e 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <list>
 
+#include <zypp/TmpPath.h>
 #include <zypp/ZYppFactory.h>
 #include <zypp/ZYpp.h>
 #include <zypp/PathInfo.h>
@@ -770,8 +771,16 @@ XMLFilesBackend::createScript(const zypp::parser::xmlstore::XMLPatchScriptData &
   try
   {
     detail::ResImplTraits<XMLScriptImpl>::Ptr impl(new XMLScriptImpl());
-    impl->_do_script = parsed.do_script;
-    impl->_undo_script = parsed.undo_script;
+    
+    ofstream file;
+    file.open(impl->_do_script.path().asString().c_str());
+    file << parsed.do_script;;
+    file.close();
+    
+    file.open(impl->_undo_script.path().asString().c_str());
+    file << parsed.undo_script;;
+    file.close();
+    
     // Collect basic Resolvable data
     NVRAD dataCollect( parsed.name, Edition( parsed.ver, parsed.rel, parsed.epoch ), Arch_noarch, createDependencies(parsed, ResTraits<Script>::kind));
     Script::Ptr script = detail::makeResolvableFromImpl( dataCollect, impl );
@@ -782,6 +791,11 @@ XMLFilesBackend::createScript(const zypp::parser::xmlstore::XMLPatchScriptData &
     ERR << excpt_r << endl;
     throw "Cannot create script object";
   }
+  catch (const std::exception & excpt_r)
+  {
+    ERR << excpt_r.what() << endl;
+    throw "Cannot create script object";
+  }
 }
 
 Language::Ptr
index 78cc3f6..8ff1e2c 100644 (file)
@@ -182,15 +182,32 @@ std::string toXML( const Script::constPtr &obj )
   // reuse Resolvable information serialize function
   out << toXML(static_cast<Resolvable::constPtr>(obj));
   out << "  <do>" << std::endl;
-  out << "      " << xml_escape(obj->do_script().asString()) << std::endl;
-#warning FIXME line above
+  out << "  <![CDATA[" << std::endl;
+  
+  // read script
+  ifstream infile;
+  infile.open(obj->do_script().asString().c_str());
+  while (infile.good())
+    out << (char) infile.get();
+  infile.close();
+  
+  out << "  ]]>" << std::endl;
   out << "  </do>" << std::endl;
+  infile.close();
   if ( obj->undo_available() )
   {
     out << "  <undo>" << std::endl;
-    out << "      " << xml_escape(obj->undo_script().asString()) << std::endl;
-#warning FIXME line above
+    out << "  <![CDATA[" << std::endl;
+  
+  // read script
+    infile.open(obj->undo_script().asString().c_str());
+    while (infile.good())
+      out << (char) infile.get();
+    infile.close();
+  
+    out << "  ]]>" << std::endl;
     out << "  </undo>" << std::endl;
+    infile.close();
   }
   out << "</script>" << std::endl;
   return out.str();
index bf0c7e9..2c1dd98 100644 (file)
@@ -29,21 +29,21 @@ namespace zypp
 
     /** Default ctor */
     XMLScriptImpl::XMLScriptImpl()
-    {}
+    {
+      _do_script = TmpFile( TmpPath::defaultLocation(), "zypp-xmlstore-do-script-");
+      _undo_script = TmpFile( TmpPath::defaultLocation(), "zypp-xmlstore-undo-script-");
+    }
+    
     /** Dtor */
     XMLScriptImpl::~XMLScriptImpl()
     {}
 
     Pathname XMLScriptImpl::do_script() const {
-       return Pathname();
-#warning FIXME
-//      return _do_script;
+      return _do_script.path();
     }
 
     Pathname XMLScriptImpl::undo_script() const {
-       return Pathname();
-#warning FIXME
-//      return _undo_script;
+        return _undo_script.path();
     }
 
     bool XMLScriptImpl::undo_available() const {
index 946d689..d4cc25a 100644 (file)
 #ifndef ZYPP_STORE_XMLSCRIPTIMPL_H
 #define ZYPP_STORE_XMLSCRIPTIMPL_H
 
+#include "zypp/TmpPath.h"
 #include "zypp/detail/ScriptImplIf.h"
 
+using namespace zypp::filesystem;
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -39,11 +42,9 @@ namespace zypp
       Pathname undo_script() const;
       /** Check whether script to undo the change is available */
       virtual bool undo_available() const;
-
-      /** The script to perform the change */
-      std::string _do_script;
-      /** The script to undo the change */
-      std::string _undo_script;
+      
+      TmpFile _do_script;
+      TmpFile _undo_script;
     };
     ///////////////////////////////////////////////////////////////////