47 template<
typename ZyppContextRefType>
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) )
93 , _medium(
std::move(medium) )
95 , _filespec(
std::move(filespec) ) {}
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();
106 return provider->provide( _medium,
_file, _filespec )
108 return verifyFile( res.
file() )
113 |
and_then( ProvideType::copyResultToDest( _ctx->zyppContext()->provider(), _ctx->destDir() /
_file ) )
115 file.resetDispose ();
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( ) {
146 if ( _filespec.checksum().empty() )
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 )
174 if ( sum == _filespec.checksum () ) {
188 MaybeAsyncRef<expected<void>> verifyFile (
const zypp::Pathname &dlFilePath ) {
192 if ( !_filespec.checksum().empty () ) {
200 CacheProviderContextRefType _ctx;