[zypp-commit] r11369 - in /trunk/libzypp: tests/zypp/MediaSetAccess_test.cc zypp/MediaSetAccess.cc zypp/MediaSetAccess.h
Author: jkupec Date: Wed Oct 15 18:00:57 2008 New Revision: 11369 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11369&view=rev Log: - MediaSetAccess::provideOptionalFile() added Modified: trunk/libzypp/tests/zypp/MediaSetAccess_test.cc trunk/libzypp/zypp/MediaSetAccess.cc trunk/libzypp/zypp/MediaSetAccess.h Modified: trunk/libzypp/tests/zypp/MediaSetAccess_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/MediaSetAccess_test.cc?rev=11369&r1=11368&r2=11369&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/MediaSetAccess_test.cc (original) +++ trunk/libzypp/tests/zypp/MediaSetAccess_test.cc Wed Oct 15 18:00:57 2008 @@ -231,5 +231,20 @@ BOOST_CHECK(check_file_exists(file3) == true); } +/* + * Provide optional file + */ +BOOST_AUTO_TEST_CASE(msa_provide_optional_file) +{ + MediaSetAccess setaccess(Url(DATADIR + "/src1/cd1")); + + // must not throw + BOOST_CHECK(setaccess.provideOptionalFile("/foo", 1).empty() == true); + + Pathname file = setaccess.provideOptionalFile("/test.txt", 1); + BOOST_CHECK(check_file_exists(file) == true); + + //! \todo test provideOptionalFile with not desired media +} // vim: set ts=2 sts=2 sw=2 ai et: Modified: trunk/libzypp/zypp/MediaSetAccess.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/MediaSetAccess.cc?rev=11369&r1=11368&r2=11369&view=diff ============================================================================== --- trunk/libzypp/zypp/MediaSetAccess.cc (original) +++ trunk/libzypp/zypp/MediaSetAccess.cc Wed Oct 15 18:00:57 2008 @@ -128,6 +128,11 @@ return provideFileInternal( file, media_nr, false, false); } + Pathname MediaSetAccess::provideOptionalFile(const Pathname & file, unsigned media_nr ) + { + return provideFileInternal( file, media_nr, false, true); + } + bool MediaSetAccess::doesFileExist(const Pathname & file, unsigned media_nr ) { callback::SendReportmedia::MediaChangeReport report; @@ -310,9 +315,9 @@ reason = media::MediaChangeReport::WRONG; } - - if (checkonly) - user = media::MediaChangeReport::ABORT; + // checkonly: only bother the user if wrong medium is in the drive + if (checkonly && reason != media::MediaChangeReport::WRONG) + return Pathname(); else { // release all media before requesting another (#336881) @@ -334,11 +339,15 @@ if( user == media::MediaChangeReport::ABORT ) { DBG << "Aborting" << endl; + if (checkonly) + return Pathname(); ZYPP_RETHROW ( excp ); } else if ( user == media::MediaChangeReport::IGNORE ) { DBG << "Skipping" << endl; + if (checkonly) + return Pathname(); SkipRequestException nexcp("User-requested skipping of a file"); nexcp.remember(excp); ZYPP_THROW(nexcp); @@ -367,6 +376,8 @@ else { DBG << "Don't know, let's ABORT" << endl; + if (checkonly) + return Pathname(); ZYPP_RETHROW ( excp ); } } while( user == media::MediaChangeReport::EJECT ); Modified: trunk/libzypp/zypp/MediaSetAccess.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/MediaSetAccess.h?rev=11369&r1=11368&r2=11369&view=diff ============================================================================== --- trunk/libzypp/zypp/MediaSetAccess.h (original) +++ trunk/libzypp/zypp/MediaSetAccess.h Wed Oct 15 18:00:57 2008 @@ -67,9 +67,9 @@ * access.setVerifier(2, media2VerifierRef); * * Pathname file1 = "/some/file/on/media1"; - * access.provideFile(1, file1); + * Pathname providedfile1 = access.provideFile(file1, 1); * Pathname file2 = "/some/file/on/media2"; - * access.provideFile(2, file1); + * Pathname providedfile2 = access.provideFile(file1, 2); * * \endcode */ @@ -131,6 +131,16 @@ Pathname provideFile(const Pathname & file, unsigned media_nr = 1 ); /** + * The same as provideFile(Pathname,unsigned) but does not throw. + * + * This method does not call the user callbacks, except of the case of + * not wrong media in the drive, but won't throw an exception in any case. + * + * \return Path to the provided file on success, an empty Pathname() otherwise. + */ + Pathname provideOptionalFile( const Pathname & file, unsigned media_nr = 1 ); + + /** * Release file from media. * This signal that file is not needed anymore. * -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
jkupec@svn.opensuse.org