libzypp: zypp/ng/repo/workflows/plaindir.cc Source File

libzypp 17.36.6

plaindir.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "plaindir.h"
10
11#include <zypp-core/zyppng/ui/ProgressObserver>
12#include <zypp-media/ng/ProvideSpec>
13#include <zypp/ng/Context>
14
15#include <zypp/ng/workflows/logichelpers.h>
16#include <zypp/ng/workflows/contextfacade.h>
17#include <zypp/ng/repo/workflows/repodownloaderwf.h>
18#include <zypp/ng/workflows/checksumwf.h>
19
20#undef ZYPP_BASE_LOGGER_LOGGROUP
21#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
22
23 namespace zyppng::PlaindirWorkflows {
24
25 namespace {
26 template<typename DlContextRefType, typename MediaHandle>
27 auto statusLogic( DlContextRefType &&ctx, MediaHandle mediaHandle ) {
28 constexpr bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
29
30 // this can only happen if this function is called with a non mounting medium, but those do not support plaindir anyway
31 if ( !mediaHandle.localPath().has_value() ) {
32 return makeReadyResult<expected<zypp::RepoStatus>, isAsync>( expected<zypp::RepoStatus>::error( ZYPP_EXCPT_PTR( zypp::Exception("Medium does not support plaindir") )) );
33 }
34
35 // dir status
36 const auto &repoInfo = std::forward<DlContextRefType>(ctx)->repoInfo();
37 auto rStatus = zypp::RepoStatus( repoInfo ) && zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() );
38 return makeReadyResult<expected<zypp::RepoStatus>, isAsync> ( expected<zypp::RepoStatus>::success(std::move(rStatus)) );
39 }
40 }
41
42 AsyncOpRef<expected<zypp::RepoStatus> > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
43 {
44 return statusLogic( std::move(dl), std::move(mediaHandle) );
45 }
46
47 expected<zypp::RepoStatus> repoStatus(repo::SyncDownloadContextRef dl, SyncMediaHandle mediaHandle)
48 {
49 return statusLogic( std::move(dl), std::move(mediaHandle) );
50 }
51
52
53 namespace {
54 template<typename DlContextRefType, typename MediaHandle>
55 auto dlLogic( DlContextRefType &&ctx, MediaHandle mediaHandle, ProgressObserverRef progressObserver ) {
56
57 constexpr bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
58 using Ret = expected<DlContextRefType>;
59
60 try {
61 // this can only happen if this function is called with a non mounting medium, but those do not support plaindir anyway
62 if ( !mediaHandle.localPath().has_value() ) {
63 return makeReadyResult<Ret, isAsync>( Ret::error( ZYPP_EXCPT_PTR( zypp::Exception("Medium does not support plaindir") )) );
64 }
65
66 if ( progressObserver ) progressObserver->inc();
67
68 // as substitute for real metadata remember the checksum of the directory we refreshed
69 const auto &repoInfo = std::forward<DlContextRefType>(ctx)->repoInfo();
70 auto newstatus = zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() ); // dir status
71
72 zypp::Pathname productpath( std::forward<DlContextRefType>(ctx)->destDir() / repoInfo.path() );
73 zypp::filesystem::assert_dir( productpath );
74 newstatus.saveToCookieFile( productpath/"cookie" );
75
76 if ( progressObserver ) progressObserver->setFinished();
77
78 } catch ( const zypp::Exception &e ) {
79 ZYPP_CAUGHT(e);
80 return makeReadyResult<Ret, isAsync>( Ret::error( ZYPP_FWD_CURRENT_EXCPT() ) );
81 } catch ( ... ) {
82 return makeReadyResult<Ret, isAsync>( Ret::error( ZYPP_FWD_CURRENT_EXCPT() ) );
83 }
84 return makeReadyResult<Ret, isAsync>( Ret::success( std::forward<DlContextRefType>(ctx) ) );
85 }
86 }
87
88 AsyncOpRef<expected<repo::AsyncDownloadContextRef> > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
89 {
90 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
91 }
92
93 expected<repo::SyncDownloadContextRef> download(repo::SyncDownloadContextRef dl, SyncMediaHandle mediaHandle, ProgressObserverRef progressObserver)
94 {
95 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
96 }
97
98}
checksumwf.h
zypp::Exception
Base class for Exception.
Definition Exception.h:147
zypp::RepoStatus
Track changing files or directories.
Definition RepoStatus.h:41
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zyppng::ProvideMediaHandle
Definition provide.h:52
zyppng::SyncMediaHandle
Definition mediafacade.h:26
zyppng::expected
Definition expected.h:27
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:115
zyppng::expected::error
E & error()
Definition expected.h:225
contextfacade.h
logichelpers.h
zypp::filesystem::assert_dir
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:324
zyppng::PlaindirWorkflows
Definition plaindir.cc:23
zyppng::PlaindirWorkflows::download
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
Definition plaindir.cc:88
zyppng::PlaindirWorkflows::repoStatus
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
Definition plaindir.cc:42
zyppng::makeReadyResult
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition asyncop.h:297
zyppng::AsyncOpRef
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
plaindir.h
repodownloaderwf.h
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:440
ZYPP_EXCPT_PTR
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:428
ZYPP_FWD_CURRENT_EXCPT
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:436