15#include <zypp-media/ng/ProvideSpec>
17#include <zypp/ZYppCallbacks.h>
18#include <zypp/MediaSetAccess.h>
20#include <zypp/repo/SUSEMediaVerifier.h>
35 const std::optional<zypp::Pathname> &
rootPath()
const;
45 void unref_to(
unsigned int)
const override;
77 return _origin.authority().url();
105 _parent->releaseMedium (
this );
119 return _data->parent();
124 return _data.get() !=
nullptr;
130 if ( !
_data )
return invalidHandle;
131 return _data->origin().authority().url();
136 static std::optional<zypp::Pathname> invalidPath;
139 return _data->rootPath();
161 if ( !handlerType ) {
162 ERR <<
"Authority URL: " << origin.
authority() <<
" is not supported!" << std::endl;
167 for (
const auto &mirror : origin.
mirrors() ) {
170 WAR <<
"URL: " << mirror <<
" is not supported, ignoring!" << std::endl;
173 if ( handlerType == *s) {
176 WAR <<
"URL: " << mirror <<
" has different handler type than the authority URL: "<< origin.
authority() <<
", ignoring!" << std::endl;
193 if ( !sanitizedOrigin.
isValid() )
197 for (
auto &ep : sanitizedOrigin )
198 ep.url() = zypp::MediaSetAccess::rewriteUrl( ep.url(), request.
medianr() );
203 return medium->isSameMedium( sanitizedOrigin, request );
212 std::optional<zypp::media::MediaAccessId> attachId;
213 zypp::callback::SendReport<zypp::media::MediaChangeReport> report;
220 attachId = mgr.
open( sanitizedOrigin );
229 auto locPath = mgr.
localPath( *attachId,
"/" );
239 if ( !zypp::callback::SendReport<zypp::media::MediaChangeReport>::connected() || !attachId ) {
244 zypp::media::MediaChangeReport::Action user = zypp::media::MediaChangeReport::ABORT;
251 auto reason = zypp::media::MediaChangeReport::INVALID;
253 reason = zypp::media::MediaChangeReport::WRONG;
256 unsigned int devindex = 0;
258 std::vector<std::string> devices;
261 std::optional<std::string> currentlyUsed;
262 if ( devices.size() ) currentlyUsed = devices[devindex];
267 devices.erase( std::remove_if( devices.begin (), devices.end(), [&](
const std::string &dev) {
268 zypp::PathInfo devInfo(dev);
269 return std::any_of( mountedDevs.begin (), mountedDevs.end(), [&devInfo]( const zypp::media::MountEntry &e ) {
270 zypp::PathInfo pi( e.src );
271 return ( pi.isBlk() && pi.devMajor() == devInfo.devMajor() && pi.devMinor() == devInfo.devMinor() );
275 if ( !devices.size () ) {
277 MIL <<
"No free device available, return jammed and try again later ( hopefully) " << std::endl;
278 if ( attachId ) mgr.
close ( *attachId );
283 bool foundCurrent =
false;
284 if ( currentlyUsed ) {
285 for (
unsigned int i = 0; i < devices.size(); i++ ) {
286 if ( devices[i] == *currentlyUsed ) {
294 if ( !foundCurrent ){
301 user = report->requestMedia (
311 MIL <<
"ProvideFile exception caught, callback answer: " << user << std::endl;
314 case zypp::media::MediaChangeReport::ABORT: {
315 DBG <<
"Aborting" << std::endl;
316 if ( attachId ) mgr.
close ( *attachId );
317 zypp::AbortRequestException aexcp(
"Aborting requested by user");
318 aexcp.remember(excp);
321 case zypp::media::MediaChangeReport::IGNORE: {
322 DBG <<
"Skipping" << std::endl;
323 if ( attachId ) mgr.
close ( *attachId );
324 zypp::SkipRequestException nexcp(
"User-requested skipping of a file");
325 nexcp.remember(excp);
328 case zypp::media::MediaChangeReport::EJECT: {
329 DBG <<
"Eject: try to release" << std::endl;
334 mgr.
release (*attachId, devindex < devices.size() ? devices[devindex] :
"");
342 case zypp::media::MediaChangeReport::RETRY:
343 case zypp::media::MediaChangeReport::CHANGE_URL: {
345 DBG <<
"Going to try again" << std::endl;
349 mgr.
close(*attachId);
354 if ( sanitizedOrigin.
authority().
url() != effectiveUrl ) {
364 DBG <<
"Don't know, let's ABORT" << std::endl;
365 if ( attachId ) mgr.
close ( *attachId );
369 }
while( user == zypp::media::MediaChangeReport::EJECT );
372 if ( attachId ) mgr.
close ( *attachId );
376 if ( attachId ) mgr.
close ( *attachId );
387 WAR <<
"Releasing zyppng::Provide with still valid MediaHandles, this is a bug!" << std::endl;
394 if ( !sanitizedOrigin.isValid() )
410 MIL <<
"Attaching lazy medium with label: [" << lazyHandle.
spec().
label() <<
"]" << std::endl;
426 std::optional<expected<ProvideRes>> lastErr;
451 url.setPathName (
"/");
464 const auto &handleInfo = attachHandle.
info();
468 if ( !mgr.
doesFileExist ( handleInfo.mediaId (), fileName ) ) {
483 if ( handleInfo.url().schemeIsDownloading() )
502 auto me = weakMe.lock();
505 return me->provide( handle, fName, req);
523 url.setPathName( source );
526 if ( !sourcePi.isExist() ) {
529 if ( !sourcePi.isFile () )
565 ERR <<
"Releasing unknown medium " << ptr->
mediaId () <<
" should not happen";
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
#define IMPL_PTR_TYPE(NAME)
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
Base class for Exception.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
const std::vector< OriginEndpoint > & mirrors() const
void setAuthority(OriginEndpoint newAuthority)
bool addMirror(OriginEndpoint newMirror)
const OriginEndpoint & authority() const
Represents a single, configurable network endpoint, combining a URL with specific access settings.
const zypp::Url & url() const
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
static bool schemeIsVolatile(const std::string &scheme_r)
cd dvd
Base class for reference counted objects.
Wrapper class for stat/lstat.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
std::shared_ptr< T > shared_this() const
std::weak_ptr< T > weak_this() const
zypp::OnMediaLocation asOnMediaLocation(const zypp::Pathname &path, unsigned int mediaNr) const
bool checkExistsOnly() const
ProvideRes(ProvideMediaHandle hdl, zypp::ManagedFile file)
const zypp::Pathname file() const
ProvideMediaHandle _provideHandle
expected< zypp::CheckSum > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin) const
expected< MediaHandle > attachMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
expected< LazyMediaHandle > prepareMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
friend class AttachedMediaInfo
expected< zypp::ManagedFile > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
expected< Res > provide(const zypp::MirroredOrigin &origin, const ProvideFileSpec &request)
::zyppng::LazyMediaHandle< Provide > LazyMediaHandle
std::vector< AttachedMediaInfo_Ptr > _attachedMedia
expected< MediaHandle > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
void releaseMedium(const AttachedMediaInfo *ptr)
ProvideMediaHandle MediaHandle
static expected success(ConsParams &&...params)
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
int unlink(const Pathname &path)
Like 'unlink'.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
ResultType and_then(const expected< T, E > &exp, Function &&f)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define ZYPP_IMPL_PRIVATE_CONSTR(Class)