[zypp-commit] r6349 - in /trunk/libzypp/zypp: PathInfo.cc PathInfo.h media/MediaCurl.cc
Author: mlandres Date: Tue Jul 31 20:00:46 2007 New Revision: 6349 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6349&view=rev Log: Added filesystem::getUmask and filesystem::applyUmaskTo (in PathInfo.h) and fixed MediaCurl to use them. Modified: trunk/libzypp/zypp/PathInfo.cc trunk/libzypp/zypp/PathInfo.h trunk/libzypp/zypp/media/MediaCurl.cc Modified: trunk/libzypp/zypp/PathInfo.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PathInfo.cc?rev=6349&r1=6348&r2=6349&view=diff ============================================================================== --- trunk/libzypp/zypp/PathInfo.cc (original) +++ trunk/libzypp/zypp/PathInfo.cc Tue Jul 31 20:00:46 2007 @@ -866,6 +866,18 @@ return ret; } + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : getUmask + // METHOD TYPE : mode_t + // + mode_t getUmask() + { + mode_t mask = ::umask( 0022 ); + ::umask( mask ); + return mask; + } + ///////////////////////////////////////////////////////////////// } // namespace filesystem /////////////////////////////////////////////////////////////////// Modified: trunk/libzypp/zypp/PathInfo.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PathInfo.h?rev=6349&r1=6348&r2=6349&view=diff ============================================================================== --- trunk/libzypp/zypp/PathInfo.h (original) +++ trunk/libzypp/zypp/PathInfo.h Tue Jul 31 20:00:46 2007 @@ -641,6 +641,22 @@ * @return Free disk space or -1 on error. **/ ByteCount df( const Pathname & path ); + + /** + * Get the current umask (file mode creation mask) + * + * @return The current umask + **/ + mode_t getUmask(); + + /** + * Modify \c mode_r according to the current umask + * <tt>( mode_r & ~getUmask() )</tt>. + * \see \ref getUmask. + * @return The resulting permissions. + **/ + inline mode_t applyUmaskTo( mode_t mode_r ) + { return mode_r & ~getUmask(); } //@} ///////////////////////////////////////////////////////////////// Modified: trunk/libzypp/zypp/media/MediaCurl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaCurl.cc?rev=6349&r1=6348&r2=6349&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaCurl.cc (original) +++ trunk/libzypp/zypp/media/MediaCurl.cc Tue Jul 31 20:00:46 2007 @@ -456,7 +456,7 @@ { DBG << "Enabling HTTP authentication methods: " << use_auth << " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl; - + ret = curl_easy_setopt( _curl, CURLOPT_HTTPAUTH, auth); if ( ret != 0 ) { disconnectFrom(); @@ -706,16 +706,16 @@ catch (MediaUnauthorizedException & ex_r) { callback::SendReport<AuthenticationReport> auth_report; - + if (!_url.getUsername().empty() && !retry) auth_data.setUserName(_url.getUsername()); - + string prompt_msg; if (retry || !_url.getUsername().empty()) prompt_msg = _("Invalid user name or password."); else // first prompt prompt_msg = boost::str(boost::format( - _("Authentication required for '%s'")) % _url.asString()); + _("Authentication required for '%s'")) % _url.asString()); // set available authentication types from the exception auth_data.setAuthType(ex_r.hint()); @@ -726,12 +726,12 @@ << "CurlAuthData: " << auth_data << endl; if (auth_data.valid()) { - _userpwd = auth_data.getUserPwd(); + _userpwd = auth_data.getUserPwd(); // set username and password CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str()); if ( ret != 0 ) ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); - + // set auth type ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType()); if ( ret != 0 ) ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); @@ -775,16 +775,16 @@ catch (MediaUnauthorizedException & ex_r) { callback::SendReport<AuthenticationReport> auth_report; - + if (!_url.getUsername().empty() && !retry) auth_data.setUserName(_url.getUsername()); - + string prompt_msg; if (retry || !_url.getUsername().empty()) prompt_msg = _("Invalid user name or password."); else // first prompt prompt_msg = boost::str(boost::format( - _("Authentication required for '%s'")) % _url.asString()); + _("Authentication required for '%s'")) % _url.asString()); // set available authentication types from the exception auth_data.setAuthType(ex_r.hint()); @@ -795,12 +795,12 @@ << "CurlAuthData: " << auth_data << endl; if (auth_data.valid()) { - _userpwd = auth_data.getUserPwd(); + _userpwd = auth_data.getUserPwd(); // set username and password CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str()); if ( ret != 0 ) ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); - + // set auth type ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType()); if ( ret != 0 ) ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); @@ -821,7 +821,7 @@ } } while (retry); - + return false; } @@ -834,7 +834,7 @@ if(_url.getHost().empty()) ZYPP_THROW(MediaBadUrlEmptyHostException(_url)); - + string path = _url.getPathName(); if ( !path.empty() && path != "/" && *path.rbegin() == '/' && filename.absolute() ) { @@ -866,7 +866,7 @@ curlUrl.setPathParams( "" ); curlUrl.setQueryString( "" ); curlUrl.setFragment( "" ); - + // // See also Bug #154197 and ftp url definition in RFC 1738: // The url "ftp://user@host/foo/bar/file" contains a path, @@ -881,22 +881,22 @@ if ( ret != 0 ) { ZYPP_THROW(MediaCurlSetOptException(url, _curlError)); } - + // set no data, because we only want to check if the file exists //ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, 1 ); //if ( ret != 0 ) { // ZYPP_THROW(MediaCurlSetOptException(url, _curlError)); - //} - - // instead of returning no data with NOBODY, we return + //} + + // instead of returning no data with NOBODY, we return // little data, that works with broken servers, and // works for ftp as well, because retrieving only headers // ftp will return always OK code ? ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-1" ); if ( ret != 0 ) { ZYPP_THROW(MediaCurlSetOptException(url, _curlError)); - } - + } + FILE *file = ::fopen( "/dev/null", "w" ); if ( !file ) { ::fclose(file); @@ -934,11 +934,11 @@ { ZYPP_THROW(MediaCurlSetOptException(url, _curlError)); } - + if ( ok != 0 ) { ::fclose( file ); - + std::string err; try { @@ -946,7 +946,7 @@ switch ( ok ) { case CURLE_FTP_COULDNT_RETR_FILE: - case CURLE_FTP_ACCESS_DENIED: + case CURLE_FTP_ACCESS_DENIED: err_file_not_found = true; break; case CURLE_HTTP_RETURNED_ERROR: @@ -961,7 +961,7 @@ str::numstring( httpReturnCode ); if ( httpReturnCode == 401 ) { - std::string auth_hint = getAuthHint(); + std::string auth_hint = getAuthHint(); DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl; DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl; @@ -1008,7 +1008,7 @@ err = "Unrecognized error"; break; } - + if( err_file_not_found) { // file does not exists @@ -1024,14 +1024,14 @@ { ZYPP_RETHROW(excpt_r); } - } - + } + // exists return ( ok == CURLE_OK ); //if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) { // WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;; //} -} +} void MediaCurl::doGetFileCopy( const Pathname & filename , const Pathname & target, callback::SendReport<DownloadProgressReport> & report) const { @@ -1176,7 +1176,7 @@ str::numstring( httpReturnCode ); if ( httpReturnCode == 401 ) { - std::string auth_hint = getAuthHint(); + std::string auth_hint = getAuthHint(); DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl; DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl; @@ -1297,11 +1297,7 @@ } #endif // DETECT_DIR_INDEX - mode_t mask; - // getumask() would be fine, but does not exist - // [ the linker can't find it in glibc :-( ]. - mask = ::umask(0022); ::umask(mask); - if ( ::fchmod( ::fileno(file), 0644 & ~mask)) + if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) ) { ERR << "Failed to chmod file " << destNew << endl; } @@ -1461,4 +1457,4 @@ } // namespace media } // namespace zypp -// +// -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
mlandres@svn.opensuse.org