11 #include <zypp-core/zyppng/ui/ProgressObserver> 12 #include <zypp-media/ng/ProvideSpec> 13 #include <zypp/ng/Context> 23 template<
typename DlContextRefType,
typename MediaHandle>
24 auto statusLogic( DlContextRefType &&ctx, MediaHandle mediaHandle ) {
25 constexpr
bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
28 if ( !mediaHandle.localPath().has_value() ) {
29 return makeReadyResult<expected<zypp::RepoStatus>, isAsync>( expected<zypp::RepoStatus>::error(
ZYPP_EXCPT_PTR(
zypp::Exception(
"Medium does not support plaindir") )) );
33 const auto &repoInfo = std::forward<DlContextRefType>(ctx)->repoInfo();
35 return makeReadyResult<expected<zypp::RepoStatus>, isAsync> ( expected<zypp::RepoStatus>::success(std::move(rStatus)) );
41 return statusLogic( std::move(dl), std::move(mediaHandle) );
46 return statusLogic( std::move(dl), std::move(mediaHandle) );
51 template<
typename DlContextRefType,
typename MediaHandle>
52 auto dlLogic( DlContextRefType &&ctx, MediaHandle mediaHandle, ProgressObserverRef progressObserver ) {
54 constexpr
bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
55 using Ret = expected<DlContextRefType>;
59 if ( !mediaHandle.localPath().has_value() ) {
63 if ( progressObserver ) progressObserver->inc();
66 const auto &repoInfo = std::forward<DlContextRefType>(ctx)->repoInfo();
67 auto newstatus =
zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() );
69 zypp::Pathname productpath( std::forward<DlContextRefType>(ctx)->destDir() / repoInfo.path() );
71 newstatus.saveToCookieFile( productpath/
"cookie" );
73 if ( progressObserver ) progressObserver->setFinished();
77 return makeReadyResult<Ret, isAsync>( Ret::error(
ZYPP_EXCPT_PTR(e) ) );
79 return makeReadyResult<Ret, isAsync>( Ret::error( std::current_exception() ) );
81 return makeReadyResult<Ret, isAsync>( Ret::success( std::forward<DlContextRefType>(ctx) ) );
85 AsyncOpRef<expected<repo::AsyncDownloadContextRef> >
download(repo::AsyncDownloadContextRef dl,
ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
87 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
90 expected<repo::SyncDownloadContextRef>
download(repo::SyncDownloadContextRef dl,
SyncMediaHandle mediaHandle, ProgressObserverRef progressObserver)
92 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Base class for Exception.
Track changing files or directories.