47 template<
typename ZyppContextRefType>
50 _cacheDirs.push_back ( p );
53 template<
typename ZyppContextRefType>
78 template <
class Executor,
class OpType>
86 using ProvideType =
typename ContextType::ProvideType;
87 using MediaHandle =
typename ProvideType::MediaHandle;
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( )
102 MIL <<
"Didn't find " <<
_file <<
" in the caches, providing from medium" << std::endl;
105 std::shared_ptr<ProvideType> provider =
_ctx->zyppContext()->provider();
108 return verifyFile( res.
file() )
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 )
143 MaybeAsyncRef<expected<zypp::ManagedFile>> findFileInCache( ) {
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 () ) {
161 auto provider =
_ctx->zyppContext()->provider();
165 return provider->checksumForFile( cacheFilePath,
_filespec.checksum().type() )
171 if ( cacheFilePath == targetFile )
188 MaybeAsyncRef<expected<void>> verifyFile (
const zypp::Pathname &dlFilePath ) {
193 return CheckSumWorkflow::verifyChecksum(
_ctx->zyppContext(),
_filespec.checksum (), std::move(dlFilePath) );
200 CacheProviderContextRefType
_ctx;
207 namespace DownloadWorkflow {