47 template<
typename ZyppContextRefType>
50 _cacheDirs.push_back ( p );
53 template<
typename ZyppContextRefType>
66 using namespace zyppng::operators;
72 :
zypp::Exception(
zypp::
str::Str() << filename <<
" not found in target cache" ) { }
78 template <
class Executor,
class OpType>
79 struct ProvideFromCacheOrMediumLogic :
public LogicBase<Executor, OpType> {
85 using ContextType =
typename remove_smart_ptr_t<CacheProviderContextRefType>::ContextType;
86 using ProvideType =
typename ContextType::ProvideType;
87 using MediaHandle =
typename ProvideType::MediaHandle;
88 using ProvideRes =
typename ProvideType::Res;
91 ProvideFromCacheOrMediumLogic( CacheProviderContextRefType cacheContext, MediaHandle &&medium,
zypp::Pathname &&file, ProvideFileSpec &&filespec )
92 :
_ctx(
std::move(cacheContext) )
97 MaybeAsyncRef<expected<zypp::ManagedFile>> execute() {
99 return findFileInCache( )
100 | [
this]( expected<zypp::ManagedFile> cached ) -> MaybeAsyncRef<expected<zypp::ManagedFile>> {
102 MIL <<
"Didn't find " <<
_file <<
" in the caches, providing from medium" << std::endl;
105 std::shared_ptr<ProvideType> provider =
_ctx->zyppContext()->provider();
107 | and_then( [
this]( ProvideRes res ) {
108 return verifyFile( res.file() )
109 | and_then( [res = res]() {
110 return expected<ProvideRes>::success( std::move(res) );
113 | and_then( ProvideType::copyResultToDest(
_ctx->zyppContext()->provider(),
_ctx->destDir() /
_file ) )
115 file.resetDispose ();
116 return make_expected_success (std::move(file));
121 return verifyFile ( cached.get() )
122 | and_then([
this, cachedFile = cached.get() ]()
mutable {
123 if ( cachedFile == _ctx->destDir() / _file ) {
124 cachedFile.resetDispose();
125 return makeReadyResult( expected<zypp::ManagedFile>::success(std::move(cachedFile) ));
128 const auto &targetPath =
_ctx->destDir() /
_file;
131 return _ctx->zyppContext()->provider()->copyFile( cachedFile,
_ctx->destDir() /
_file )
132 | and_then( [cachedFile](
zypp::ManagedFile &&f) { f.resetDispose();
return make_expected_success (std::move(f)); });
143 MaybeAsyncRef<expected<zypp::ManagedFile>> findFileInCache( ) {
147 return makeReadyResult( expected<zypp::ManagedFile>::error(std::make_exception_ptr( CacheMissException(
_file) )) );
149 const auto &confDirs =
_ctx->cacheDirs();
150 const auto targetFile =
_ctx->destDir() /
_file ;
151 std::vector<zypp::Pathname> caches;
152 caches.push_back(
_ctx->destDir() );
153 caches.insert( caches.end(), confDirs.begin(), confDirs.end() );
155 auto makeSearchPipeline = [
this, targetFile](
zypp::Pathname cachePath ){
158 if ( !cacheFileInfo.isExist () ) {
159 return makeReadyResult(expected<zypp::ManagedFile>::error( std::make_exception_ptr (CacheMissException(
_file)) ));
161 auto provider =
_ctx->zyppContext()->provider();
165 return provider->checksumForFile( cacheFilePath,
_filespec.checksum().type() )
166 | and_then([
this, cacheFilePath, targetFile](
zypp::CheckSum sum ) {
171 if ( cacheFilePath == targetFile )
176 return expected<zypp::ManagedFile>::success( std::move(mgdFile) );
179 return expected<zypp::ManagedFile>::error( std::make_exception_ptr (CacheMissException(
_file)) );
184 auto defVal = expected<zypp::ManagedFile>::error( std::make_exception_ptr (CacheMissException(
_file) ) );
185 return std::move(caches) | firstOf( std::move(makeSearchPipeline), std::move(defVal), detail::ContinueUntilValidPredicate() );
188 MaybeAsyncRef<expected<void>> verifyFile (
const zypp::Pathname &dlFilePath ) {
193 return CheckSumWorkflow::verifyChecksum(
_ctx->zyppContext(),
_filespec.checksum (), std::move(dlFilePath) );
195 return makeReadyResult(expected<void>::success());
200 CacheProviderContextRefType
_ctx;
207 namespace DownloadWorkflow {