libzypp 17.37.17
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
19
20#undef ZYPP_BASE_LOGGER_LOGGROUP
21#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
22
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() ) {
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() );
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>;
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);
81 } catch ( ... ) {
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}
Base class for Exception.
Definition Exception.h:153
Track changing files or directories.
Definition RepoStatus.h:41
static expected success(ConsParams &&...params)
Definition expected.h:115
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:324
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
Definition plaindir.cc:88
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
Definition plaindir.cc:42
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition asyncop.h:297
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471