From 8ed2e77fb33c00ee127ddabe7e17e0b7520c0ad1 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 28 May 2008 13:33:50 +0000 Subject: [PATCH] - Create missing directories when saving config files. (bnc #395026) - Fix undefined behaviour in RepoManager. --- devel/devel.ma/Tools.h | 1 + package/libzypp.changes | 7 +++++++ zypp/RepoManager.cc | 16 +++++++++------- zypp/TmpPath.cc | 19 +++++++++++++++---- zypp/TmpPath.h | 2 -- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/devel/devel.ma/Tools.h b/devel/devel.ma/Tools.h index 3f958ac..1683fee 100644 --- a/devel/devel.ma/Tools.h +++ b/devel/devel.ma/Tools.h @@ -112,6 +112,7 @@ template inline RepoManager makeRepoManager( const Pathname & mgrdir_r ) { + return RepoManager(); RepoManagerOptions mgropt; mgropt.repoCachePath = mgrdir_r/"cache"; diff --git a/package/libzypp.changes b/package/libzypp.changes index d3beb62..4fe2e67 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Wed May 28 15:30:24 CEST 2008 - ma@suse.de + +- Create missing directories when saving config files. (bnc #395026) +- Fix undefined behaviour in RepoManager. +- revision 10255 + +------------------------------------------------------------------- Wed May 28 15:23:44 CEST 2008 - schubi@suse.de - SOLVER_ERASE_SOLVABLE_NAME: As we do not know, if this request has come diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index defb77e..8a2c6f0 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -772,16 +772,18 @@ namespace zypp ManagedFile guard( solvfile, filesystem::unlink ); ostringstream cmd; - const char *toFile = str::gsub(solvfile.asString(),"\"","\\\"").c_str(); + std::string toFile( str::gsub(solvfile.asString(),"\"","\\\"") ); if ( repokind.toEnum() == RepoType::RPMPLAINDIR_e ) { - const char * from = str::gsub( - info.baseUrlsBegin()->getPathName(),"\"","\\\"").c_str(); - cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"", from , toFile ); - } else + cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"", + str::gsub( info.baseUrlsBegin()->getPathName(),"\"","\\\"" ).c_str(), + toFile.c_str() ); + } + else { - const char * from = str::gsub(rawpath.asString(),"\"","\\\"").c_str(); - cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"", from, toFile ); + cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"", + str::gsub( rawpath.asString(),"\"","\\\"" ).c_str(), + toFile.c_str() ); } MIL << "Executing: " << cmd.str() << endl; ExternalProgram prog( cmd.str(), ExternalProgram::Stderr_To_Stdout ); diff --git a/zypp/TmpPath.cc b/zypp/TmpPath.cc index 246d180..b8e89c7 100644 --- a/zypp/TmpPath.cc +++ b/zypp/TmpPath.cc @@ -175,8 +175,13 @@ namespace zypp { PathInfo p( inParentDir_r ); if ( ! p.isDir() ) { - ERR << "Parent directory does not exist: " << p << endl; - return; + filesystem::assert_dir( inParentDir_r ); + p(); // re-stat + if ( ! p.isDir() ) + { + ERR << "Parent directory can't be created: " << p << endl; + return; + } } // create the temp file @@ -185,6 +190,7 @@ namespace zypp { if ( ! buf ) { ERR << "Out of memory" << endl; + ::free( buf ); return; } @@ -248,8 +254,13 @@ namespace zypp { PathInfo p( inParentDir_r ); if ( ! p.isDir() ) { - ERR << "Parent directory does not exist: " << p << endl; - return; + filesystem::assert_dir( inParentDir_r ); + p(); // re-stat + if ( ! p.isDir() ) + { + ERR << "Parent directory does not exist: " << p << endl; + return; + } } // create the temp dir diff --git a/zypp/TmpPath.h b/zypp/TmpPath.h index ad2b6ce..bab81e3 100644 --- a/zypp/TmpPath.h +++ b/zypp/TmpPath.h @@ -109,7 +109,6 @@ namespace zypp { * name unique. Different location and file prefix may be passed to * the ctor. TmpFile is created with mode 0600. * - * The directory where the temporary file is to be created must exist. * TmpFile provides the Pathname of the temporary file, or an empty * path in case of any error. **/ @@ -154,7 +153,6 @@ namespace zypp { * the name unique. Different location and file prefix may be passed * to the ctor. TmpDir is created with mode 0700. * - * The directory where the temporary directory is to be created must exist. * TmpDir provides the Pathname of the temporary directory , or an empty * path in case of any error. **/ -- 2.7.4