libzypp 17.32.2
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
21
22 namespace {
23 template<typename DlContextRefType, typename MediaHandle>
24 auto statusLogic( DlContextRefType &&ctx, MediaHandle mediaHandle ) {
25 constexpr bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
26
27 // this can only happen if this function is called with a non mounting medium, but those do not support plaindir anyway
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") )) );
30 }
31
32 // dir status
33 const auto &repoInfo = std::forward<DlContextRefType>(ctx)->repoInfo();
34 auto rStatus = zypp::RepoStatus( repoInfo ) && zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() );
35 return makeReadyResult<expected<zypp::RepoStatus>, isAsync> ( expected<zypp::RepoStatus>::success(std::move(rStatus)) );
36 }
37 }
38
39 AsyncOpRef<expected<zypp::RepoStatus> > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
40 {
41 return statusLogic( std::move(dl), std::move(mediaHandle) );
42 }
43
44 expected<zypp::RepoStatus> repoStatus(repo::SyncDownloadContextRef dl, SyncMediaHandle mediaHandle)
45 {
46 return statusLogic( std::move(dl), std::move(mediaHandle) );
47 }
48
49
50 namespace {
51 template<typename DlContextRefType, typename MediaHandle>
52 auto dlLogic( DlContextRefType &&ctx, MediaHandle mediaHandle, ProgressObserverRef progressObserver ) {
53
54 constexpr bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
55 using Ret = expected<DlContextRefType>;
56
57 try {
58 // this can only happen if this function is called with a non mounting medium, but those do not support plaindir anyway
59 if ( !mediaHandle.localPath().has_value() ) {
60 return makeReadyResult<Ret, isAsync>( Ret::error( ZYPP_EXCPT_PTR( zypp::Exception("Medium does not support plaindir") )) );
61 }
62
63 if ( progressObserver ) progressObserver->inc();
64
65 // as substitute for real metadata remember the checksum of the directory we refreshed
66 const auto &repoInfo = std::forward<DlContextRefType>(ctx)->repoInfo();
67 auto newstatus = zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() ); // dir status
68
69 zypp::Pathname productpath( std::forward<DlContextRefType>(ctx)->destDir() / repoInfo.path() );
70 zypp::filesystem::assert_dir( productpath );
71 newstatus.saveToCookieFile( productpath/"cookie" );
72
73 if ( progressObserver ) progressObserver->setFinished();
74
75 } catch ( const zypp::Exception &e ) {
76 ZYPP_CAUGHT(e);
77 return makeReadyResult<Ret, isAsync>( Ret::error( ZYPP_EXCPT_PTR(e) ) );
78 } catch ( ... ) {
79 return makeReadyResult<Ret, isAsync>( Ret::error( std::current_exception() ) );
80 }
81 return makeReadyResult<Ret, isAsync>( Ret::success( std::forward<DlContextRefType>(ctx) ) );
82 }
83 }
84
85 AsyncOpRef<expected<repo::AsyncDownloadContextRef> > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
86 {
87 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
88 }
89
90 expected<repo::SyncDownloadContextRef> download(repo::SyncDownloadContextRef dl, SyncMediaHandle mediaHandle, ProgressObserverRef progressObserver)
91 {
92 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
93 }
94
95}
Base class for Exception.
Definition Exception.h:147
Track changing files or directories.
Definition RepoStatus.h:41
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:320
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
Definition plaindir.cc:85
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
Definition plaindir.cc:39
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:437
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:433