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

libzypp 17.38.11

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/ng/ui/ProgressObserver>
12#include <zypp-media/ng/ProvideSpec>
13#include <zypp/ng/Context>
14
15
16#include <zypp/ng/repo/workflows/repodownloaderwf.h>
17#include <zypp/ng/workflows/checksumwf.h>
18
19#undef ZYPP_BASE_LOGGER_LOGGROUP
20#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
21
22 namespace zyppng::PlaindirWorkflows {
23
24 namespace {
25 auto statusLogic( repo::DownloadContextRef &&ctx, ProvideMediaHandle mediaHandle ) {
26 // this can only happen if this function is called with a non mounting medium, but those do not support plaindir anyway
27 if ( !mediaHandle.localPath().has_value() ) {
28 return makeReadyTask<expected<zypp::RepoStatus>>( expected<zypp::RepoStatus>::error( ZYPP_EXCPT_PTR( zypp::Exception("Medium does not support plaindir") )) );
29 }
30
31 // dir status
32 const auto &repoInfo = std::forward<repo::DownloadContextRef>(ctx)->repoInfo();
33 auto rStatus = zypp::RepoStatus( repoInfo ) && zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() );
34 return makeReadyTask<expected<zypp::RepoStatus>> ( expected<zypp::RepoStatus>::success(std::move(rStatus)) );
35 }
36 }
37
38 MaybeAwaitable<expected<zypp::RepoStatus> > repoStatus(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle)
39 {
40 return statusLogic( std::move(dl), std::move(mediaHandle) );
41 }
42
43 namespace {
44 auto dlLogic( repo::DownloadContextRef &&ctx, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver ) {
45 using Ret = expected<repo::DownloadContextRef>;
46
47 try {
48 // this can only happen if this function is called with a non mounting medium, but those do not support plaindir anyway
49 if ( !mediaHandle.localPath().has_value() ) {
50 return makeReadyTask<Ret>( Ret::error( ZYPP_EXCPT_PTR( zypp::Exception("Medium does not support plaindir") )) );
51 }
52
53 if ( progressObserver ) progressObserver->inc();
54
55 // as substitute for real metadata remember the checksum of the directory we refreshed
56 const auto &repoInfo = std::forward<repo::DownloadContextRef>(ctx)->repoInfo();
57 auto newstatus = zypp::RepoStatus( mediaHandle.localPath().value() / repoInfo.path() ); // dir status
58
59 zypp::Pathname productpath( std::forward<repo::DownloadContextRef>(ctx)->destDir() / repoInfo.path() );
60 zypp::filesystem::assert_dir( productpath );
61 newstatus.saveToCookieFile( productpath/"cookie" );
62
63 if ( progressObserver ) progressObserver->setFinished();
64
65 } catch ( const zypp::Exception &e ) {
66 ZYPP_CAUGHT(e);
67 return makeReadyTask<Ret>( Ret::error( ZYPP_FWD_CURRENT_EXCPT() ) );
68 } catch ( ... ) {
69 return makeReadyTask<Ret>( Ret::error( ZYPP_FWD_CURRENT_EXCPT() ) );
70 }
71 return makeReadyTask<Ret>( Ret::success( std::forward<repo::DownloadContextRef>(ctx) ) );
72 }
73 }
74
75 MaybeAwaitable<expected<repo::DownloadContextRef> > download(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
76 {
77 return dlLogic( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
78 }
79}
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
ZYPP_EXCPT_PTR
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
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:471
checksumwf.h
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::RepoStatus
Track changing files or directories.
Definition RepoStatus.h:41
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zyppng::ProvideMediaHandle
Definition provide.h:27
zyppng::ProvideMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition provide.cc:134
zyppng::expected
Definition expected.h:56
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:178
zyppng::expected::error
E & error()
Definition expected.h:288
zypp::filesystem::assert_dir
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:338
zyppng::PlaindirWorkflows
Definition plaindir.cc:22
zyppng::PlaindirWorkflows::download
MaybeAwaitable< expected< repo::DownloadContextRef > > download(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
Definition plaindir.cc:75
zyppng::PlaindirWorkflows::repoStatus
MaybeAwaitable< expected< zypp::RepoStatus > > repoStatus(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle)
Definition plaindir.cc:38
plaindir.h
repodownloaderwf.h