18 #include <zypp-core/ng/pipelines/Algorithm> 21 #include <zypp-media/ng/ProvideSpec> 27 , _destDir(
std::move(destDir) )
66 struct ProvideFromCacheOrMediumLogic {
69 using ContextType = Context;
70 using ProvideType =
typename ContextType::ProvideType;
71 using MediaHandle =
typename ProvideType::MediaHandle;
75 ProvideFromCacheOrMediumLogic( CacheProviderContextRef cacheContext, MediaHandle &&medium,
zypp::Pathname &&file, ProvideFileSpec &&filespec )
76 :
_ctx(
std::move(cacheContext) )
81 MaybeAwaitable<expected<zypp::ManagedFile>> execute() {
83 return findFileInCache( )
84 | [
this]( expected<zypp::ManagedFile> cached ) -> MaybeAwaitable<expected<zypp::ManagedFile>> {
86 MIL <<
"Didn't find " <<
_file <<
" in the caches, providing from medium" << std::endl;
89 std::shared_ptr<ProvideType> provider =
_ctx->zyppContext()->provider();
92 return verifyFile( res.file() )
97 |
and_then( ProvideType::copyResultToDest(
_ctx->zyppContext()->provider(),
_ctx->destDir() /
_file ) )
105 return verifyFile ( cached.get() )
106 |
and_then([
this, cachedFile = cached.get() ]()
mutable {
107 if ( cachedFile ==
_ctx->destDir() /
_file ) {
108 cachedFile.resetDispose();
112 const auto &targetPath =
_ctx->destDir() /
_file;
115 return _ctx->zyppContext()->provider()->copyFile( cachedFile,
_ctx->destDir() /
_file )
126 MaybeAwaitable<expected<zypp::ManagedFile>> findFileInCache( ) {
132 const auto &confDirs =
_ctx->cacheDirs();
133 const auto targetFile =
_ctx->destDir() /
_file ;
134 std::vector<zypp::Pathname> caches;
135 caches.push_back(
_ctx->destDir() );
136 caches.insert( caches.end(), confDirs.begin(), confDirs.end() );
138 auto makeSearchPipeline = [
this, targetFile](
zypp::Pathname cachePath ) -> expected<zypp::ManagedFile> {
141 if ( !cacheFileInfo.isExist () ) {
144 auto provider =
_ctx->zyppContext()->provider();
148 return provider->checksumForFile( cacheFilePath,
_filespec.checksum().type() )
154 if ( cacheFilePath == targetFile )
168 return std::move(caches) |
firstOf( std::move(makeSearchPipeline), std::move(defVal), detail::ContinueUntilValidPredicate() );
171 MaybeAwaitable<expected<void>> verifyFile (
const zypp::Pathname &dlFilePath ) {
190 namespace DownloadWorkflow {
194 ProvideFromCacheOrMediumLogic impl(std::move(cacheContext), std::move(medium), std::move(file), std::move(filespec));
195 zypp_co_return zypp_co_await( impl.execute() );
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::vector< zypp::Pathname > _cacheDirs
void addCacheDir(const zypp::Pathname &p)
String related utilities and Regular expression matching.
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
auto firstOf(Transformation &&transformFunc, DefaultType &&def, Predicate &&predicate=detail::ContinueUntilValidPredicate())
MaybeAwaitable< expected< zypp::ManagedFile > > provideToCacheDir(CacheProviderContextRef cacheContext, ProvideMediaHandle medium, zypp::Pathname file, ProvideFileSpec filespec)
int unlink(const Pathname &path)
Like 'unlink'.
static expected success(ConsParams &&...params)
MaybeAwaitable< expected< void > > verifyChecksum(ContextRef zyppCtx, zypp::CheckSum checksum, zypp::filesystem::Pathname file)
#define ZYPP_PRIVATE_CONSTR_ARG
Base class for Exception.
auto and_then(Fun &&function)
Wrapper class for ::stat/::lstat.
const zypp::Pathname & destDir() const
const std::vector< zypp::Pathname > & cacheDirs() const
ProvideFileSpec _filespec
CacheProviderContextRef _ctx
Easy-to use interface to the ZYPP dependency resolver.
const ContextRef & zyppContext() const