Author: jkupec Date: Mon Jul 9 19:47:00 2007 New Revision: 39259 URL: http://svn.opensuse.org/viewcvs/yast?rev=39259&view=rev Log: ProvideFile and ProvideDir reimplemented Modified: branches/REFACTORING-10_3/pkg-bindings/src/PkgModuleFunctions.h branches/REFACTORING-10_3/pkg-bindings/src/Source.cc Modified: branches/REFACTORING-10_3/pkg-bindings/src/PkgModuleFunctions.h URL: http://svn.opensuse.org/viewcvs/yast/branches/REFACTORING-10_3/pkg-bindings/src/PkgModuleFunctions.h?rev=39259&r1=39258&r2=39259&view=diff ============================================================================== --- branches/REFACTORING-10_3/pkg-bindings/src/PkgModuleFunctions.h (original) +++ branches/REFACTORING-10_3/pkg-bindings/src/PkgModuleFunctions.h Mon Jul 9 19:47:00 2007 @@ -147,7 +147,10 @@ zypp::RepoInfo& logFindRepository(zypp::Repository::NumericId id); zypp::Repository::NumericId createManagedSource(const zypp::Url & url_r, const zypp::Pathname & path_r, const bool base_source, const std::string& type); - + /** + * provides SourceProvideFile and SourceProvideFileCommon + */ + YCPValue SourceProvideFileCommon (const YCPInteger&, const YCPInteger&, const YCPString&, const YCPBoolean&); public: // general /* TYPEINFO: void() */ Modified: branches/REFACTORING-10_3/pkg-bindings/src/Source.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/REFACTORING-10_3/pkg-bindings/src/Source.cc?rev=39259&r1=39258&r2=39259&view=diff ============================================================================== --- branches/REFACTORING-10_3/pkg-bindings/src/Source.cc (original) +++ branches/REFACTORING-10_3/pkg-bindings/src/Source.cc Mon Jul 9 19:47:00 2007 @@ -729,56 +729,28 @@ return YCPMap(); } -/* -void SourceProvideFileEx(const zypp::RepoInfo &rep, const std::string &file, - const std::string &cachedir, const std::string &targetdir, bool optional = true) -// TODO: add directory and recursive parameter -{ - try { - zypp::OnMediaLocation oml; - oml.medianr(mid->value()); - oml.filename(f->value()); - - zypp::MediaSetAccess maccess(*src.baseUrlsBegin()); - - zypp::Fetcher fetcher; - fetcher.enqueue(oml); - fetcher.addCachePath(cachedir); - fetcher.start(targetdir, maccess); - fetcher.reset(); - } - catch (const zypp::Exception& excpt) - { - _last_error.setLastError(excpt.asUserString()); - y2milestone ("File not found: %s", f->value_cstr()); - } -} -*/ -/**************************************************************************************** - * @builtin SourceProvideFile - * - * @short Make a file available at the local filesystem - * @description - * Let an InstSrc provide some file (make it available at the local filesystem). - * - * @param integer SrcId Specifies the InstSrc . - * @param integer medianr Number of the media the file is located on ('1' for the 1st media). - * @param string file Filename relative to the media root. - * - * @return string local path as string - **/ -YCPValue -PkgModuleFunctions::SourceProvideFile (const YCPInteger& id, const YCPInteger& mid, const YCPString& f) +YCPValue PkgModuleFunctions::SourceProvideFileCommon(const YCPInteger &id, + const YCPInteger &mid, + const YCPString& f, + const YCPBoolean & optional) { CallSourceReportInit(); CallSourceReportStart(_("Downloading file...")); -#warning TODO: use SourceProvideFileEx() zypp::RepoInfo src; bool found = true; - try { + extern ZyppRecipients::MediaChangeSensitivity _silent_probing; + // remember the current value + ZyppRecipients::MediaChangeSensitivity _silent_probing_old = _silent_probing; + + // disable media change callback for optional file + if (optional->value()) + _silent_probing = ZyppRecipients::MEDIA_CHANGE_OPTIONALFILE; + + try + { src = logFindRepository(id->value()); } catch (const zypp::Exception& excpt) @@ -790,28 +762,25 @@ if (found) { - try { - zypp::OnMediaLocation oml; - oml.setMedianr(mid->value()); - oml.setFilename(f->value()); - + try + { zypp::MediaSetAccess maccess(*src.baseUrlsBegin()); - - zypp::Fetcher fetcher; - fetcher.enqueue(oml); - # warning TODO FIXME: use MediaSetAccess only (without Fetcher) ?? - fetcher.addCachePath("/tmp/cache"); - fetcher.start("/download-dir", maccess); - fetcher.reset(); + path = maccess.provideFile(f->value(), mid->value()); } catch (const zypp::Exception& excpt) { - _last_error.setLastError(excpt.asUserString()); - y2milestone ("File not found: %s", f->value_cstr()); - found = false; + if (!optional->value()) + { + _last_error.setLastError(excpt.asUserString()); + y2milestone ("File not found: %s", f->value_cstr()); + found = false; + } } } + // set the original probing value + _silent_probing = _silent_probing_old; + CallSourceReportEnd(_("Downloading file...")); CallSourceReportDestroy(); @@ -823,7 +792,26 @@ { return YCPVoid(); } +} + +/**************************************************************************************** + * @builtin SourceProvideFile + * + * @short Make a file available at the local filesystem + * @description + * Let an InstSrc provide some file (make it available at the local filesystem). + * + * @param integer SrcId Specifies the InstSrc . + * @param integer medianr Number of the media the file is located on ('1' for the 1st media). + * @param string file Filename relative to the media root. + * + * @return string local path as string + **/ +YCPValue +PkgModuleFunctions::SourceProvideFile (const YCPInteger& id, const YCPInteger& mid, const YCPString& f) +{ + return SourceProvideFileCommon(id, mid, f, false /*optional*/); } /**************************************************************************************** @@ -843,62 +831,7 @@ YCPValue PkgModuleFunctions::SourceProvideOptionalFile (const YCPInteger& id, const YCPInteger& mid, const YCPString& f) { -#warning TODO: use SourceProvideFileEx() - CallSourceReportInit(); - CallSourceReportStart(_("Downloading files...")); - - YCPValue ret; - - extern ZyppRecipients::MediaChangeSensitivity _silent_probing; - - // remember the current value - ZyppRecipients::MediaChangeSensitivity _silent_probing_old = _silent_probing; - - // disable media change callback - _silent_probing = ZyppRecipients::MEDIA_CHANGE_OPTIONALFILE; - - bool found = true; - zypp::filesystem::Pathname path; -#warning FIXME SourceProvideOptionalFile is NOT implemented!!! -/* - zypp::Source_Ref src; - - try { - src = logFindRepository(id->value()); - } - catch (const zypp::Exception& excpt) - { - found = false; - } - - if (found) - { - try { - path = src.provideFile(f->value(), mid->asInteger()->value()); - } - catch (const zypp::Exception& excpt) - { - found = false; - // the file is optional, don't set error flag here - } - } - - */ - // set the original probing value - _silent_probing = _silent_probing_old; - - - CallSourceReportEnd(_("Downloading files...")); - CallSourceReportDestroy(); - - if (found) - { - return YCPString(path.asString()); - } - else - { - return YCPVoid(); - } + return SourceProvideFileCommon(id, mid, f, true /*optional*/); } /**************************************************************************************** @@ -916,33 +849,43 @@ YCPValue PkgModuleFunctions::SourceProvideDir (const YCPInteger& id, const YCPInteger& mid, const YCPString& d) { -#warning FIXME SourceProvideDir is NOT implemented!!! - /* - zypp::Source_Ref src; + zypp::RepoInfo src; + bool found = true; try { - src = logFindRepository(id->value()); + src = logFindRepository(id->value()).info(); } catch (const zypp::Exception& excpt) { - return YCPVoid (); + found = false; } -*/ + zypp::filesystem::Pathname path; -/* - try + + if (found) { - path = src.provideDirTree(d->value(), mid->asInteger()->value()); + try + { + zypp::MediaSetAccess maccess(*src.baseUrlsBegin()); + path = maccess.provideDir(d->value(), true, mid->value()); + } + catch (const zypp::Exception& excpt) + { + _last_error.setLastError(excpt.asUserString()); + y2milestone ("Directory not found: %s", d->value_cstr()); + found = false; + } } - catch (const zypp::Exception& excpt) + + if (found) + { + return YCPString(path.asString()); + } + else { - _last_error.setLastError(excpt.asUserString()); - y2milestone ("Directory not found: %s", d->value_cstr()); return YCPVoid(); } -*/ - return YCPString(path.asString()); } /**************************************************************************************** -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org