forward port #192535
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 1 Aug 2006 11:19:30 +0000 (11:19 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 1 Aug 2006 11:19:30 +0000 (11:19 +0000)
zypp/source/yum/YUMScriptImpl.cc
zypp/source/yum/YUMScriptImpl.h
zypp/target/store/XMLFilesBackend.cc
zypp/target/store/xml/XMLScriptImpl.cc
zypp/target/store/xml/XMLScriptImpl.h

index 873f0fb..6adcf69 100644 (file)
@@ -66,11 +66,17 @@ namespace zypp
        if (_do_script != "")
        {
          if ( !_tmp_do_script )
-            _tmp_do_script.reset(new filesystem::TmpDir(getZYpp()->tmpPath()));
+            _tmp_do_script.reset(new filesystem::TmpFile(getZYpp()->tmpPath(), "zypp-yum-do-script-"));
 
           Pathname pth = _tmp_do_script->path();
           // FIXME check success
           ofstream st(pth.asString().c_str());
+
+          if ( !st )
+          {
+            ZYPP_THROW(Exception(N_("Can't write the patch script to a temporary file.")));
+          }
+
           st << _do_script << endl;
           return pth;
        }
@@ -94,11 +100,17 @@ namespace zypp
        if (_undo_script != "")
        {
           if ( !_tmp_undo_script )
-            _tmp_undo_script.reset(new filesystem::TmpDir(getZYpp()->tmpPath()));
+            _tmp_undo_script.reset(new filesystem::TmpFile(getZYpp()->tmpPath(), "zypp-yum-undo-script-"));
 
           Pathname pth = _tmp_undo_script->path();
           // FIXME check success
           ofstream st(pth.asString().c_str());
+        
+          if ( !st )
+          {
+            ZYPP_THROW(Exception(N_("Can't write the patch script to a temporary file.")));
+          }
+
           st << _undo_script << endl;
           return pth;
        }
index ef8281a..aa4e5fd 100644 (file)
@@ -61,8 +61,8 @@ namespace zypp
        /** Media number of the undo script */
        unsigned _undo_media;
 
-        mutable shared_ptr<filesystem::TmpDir> _tmp_do_script;
-        mutable shared_ptr<filesystem::TmpDir> _tmp_undo_script;
+        mutable shared_ptr<filesystem::TmpFile> _tmp_do_script;
+        mutable shared_ptr<filesystem::TmpFile> _tmp_undo_script;
 
        CheckSum _do_checksum;
        CheckSum _undo_checksum;
index 58aa73d..d1ef012 100644 (file)
@@ -908,11 +908,18 @@ XMLFilesBackend::createScript(const zypp::parser::xmlstore::XMLPatchScriptData &
     detail::ResImplTraits<XMLScriptImpl>::Ptr impl(new XMLScriptImpl());
 
     ofstream file;
-    file.open(impl->_do_script.path().asString().c_str());
+    file.open(impl->_do_script->path().asString().c_str());
+
+    if ( ! file )
+      ZYPP_THROW(Exception(N_("Can't write the patch script to a temporary file.")));
+
     file << parsed.do_script;;
     file.close();
 
-    file.open(impl->_undo_script.path().asString().c_str());
+    file.open(impl->_undo_script->path().asString().c_str());
+    if ( ! file )
+      ZYPP_THROW(Exception(N_("Can't write the patch script to a temporary file.")));
+
     file << parsed.undo_script;;
     file.close();
 
index 2c1dd98..9ed5b71 100644 (file)
@@ -30,8 +30,8 @@ namespace zypp
     /** Default ctor */
     XMLScriptImpl::XMLScriptImpl()
     {
-      _do_script = TmpFile( TmpPath::defaultLocation(), "zypp-xmlstore-do-script-");
-      _undo_script = TmpFile( TmpPath::defaultLocation(), "zypp-xmlstore-undo-script-");
+      _do_script.reset( new TmpFile( TmpPath::defaultLocation(), "zypp-xmlstore-do-script-") );
+      _undo_script.reset( new TmpFile( TmpPath::defaultLocation(), "zypp-xmlstore-undo-script-"));
     }
     
     /** Dtor */
@@ -39,15 +39,15 @@ namespace zypp
     {}
 
     Pathname XMLScriptImpl::do_script() const {
-      return _do_script.path();
+      return _do_script->path();
     }
 
     Pathname XMLScriptImpl::undo_script() const {
-        return _undo_script.path();
+        return _undo_script->path();
     }
 
     bool XMLScriptImpl::undo_available() const {
-      return _undo_script != "";
+      return *_undo_script != "";
     }
 
     /////////////////////////////////////////////////////////////////
index f76ae04..fee943c 100644 (file)
@@ -68,9 +68,9 @@ namespace zypp
       /** Check whether script to undo the change is available */
       virtual bool undo_available() const;
       
-      TmpFile _do_script;
-      TmpFile _undo_script;
-      
+      mutable shared_ptr<filesystem::TmpFile> _do_script;
+      mutable shared_ptr<filesystem::TmpFile> _undo_script;      
+
       TranslatedText _summary;
       TranslatedText _description;