14 #include <zypp/ng/Context> 20 #include <zypp-core/zyppng/pipelines/Algorithm> 22 #include <zypp-media/ng/Provide> 23 #include <zypp-media/ng/ProvideSpec> 27 template<
typename ZyppContextRefType>
30 , _destDir(
std::move(destDir) )
34 template<
typename ZyppContextRefType>
41 template<
typename ZyppContextRefType>
47 template<
typename ZyppContextRefType>
50 _cacheDirs.push_back ( p );
53 template<
typename ZyppContextRefType>
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() )
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();
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 )
185 return std::move(caches) |
firstOf( std::move(makeSearchPipeline), std::move(defVal), detail::ContinueUntilValidPredicate() );
188 MaybeAsyncRef<expected<void>> verifyFile (
const zypp::Pathname &dlFilePath ) {
200 CacheProviderContextRefType
_ctx;
207 namespace DownloadWorkflow {
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
CacheProviderContextRefType _ctx
String related utilities and Regular expression matching.
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
expected< zypp::ManagedFile > provideToCacheDir(SyncCacheProviderContextRef cacheContext, SyncMediaHandle medium, zypp::Pathname file, ProvideFileSpec filespec)
ZyppContextRefType _zyppContext
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())
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
typename conditional< B, T, F >::type conditional_t
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
int unlink(const Pathname &path)
Like 'unlink'.
static expected success(ConsParams &&...params)
std::shared_ptr< AsyncOp< T > > AsyncOpRef
#define ZYPP_PRIVATE_CONSTR_ARG
Base class for Exception.
auto and_then(Fun &&function)
Wrapper class for ::stat/::lstat.
expected< void > verifyChecksum(SyncContextRef zyppCtx, zypp::CheckSum checksum, zypp::Pathname file)
ZyppContextRefType ContextRefType
ProvideFileSpec _filespec
Easy-to use interface to the ZYPP dependency resolver.