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;
59 , _origin(
std::move( origin ) )
60 , _spec(
std::move( mediaSpec ))
61 , _parent(
std::move( parentRef ))
62 , _localPath( locPath )
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();
148 : _res(
std::move(file) )
149 , _provideHandle(
std::move (hdl) )
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) {
174 sanitized.addMirror(mirror);
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,
"/" );
230 auto attachInfo = AttachedMediaInfo_Ptr(
new AttachedMediaInfo( shared_this<Provide>(), *attachId, std::move(sanitizedOrigin), request, locPath ) );
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) {
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 );
386 if ( _attachedMedia.size () ) {
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;
449 zypp::Url url( origin.authority().url() );
451 url.setPathName (
"/");
464 const auto &handleInfo = attachHandle.
info();
468 if ( !mgr.
doesFileExist ( handleInfo.mediaId (), fileName ) ) {
483 if ( handleInfo.url().schemeIsDownloading() )
501 |
and_then([weakMe = weak_this<Provide>(), fName = fileName, req = request ](
MediaHandle handle ){
502 auto me = weakMe.lock();
505 return me->provide( handle, fName, req);
526 if ( !sourcePi.isExist() ) {
529 if ( !sourcePi.isFile () )
565 ERR <<
"Releasing unknown medium " << ptr->
mediaId () <<
" should not happen";
friend class AttachedMediaInfo
const zypp::Url & url() const
ZYPP_IMPL_PRIVATE_CONSTR(Context)
std::vector< AttachedMediaInfo_Ptr > _attachedMedia
unsigned int devMinor() const
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
zypp::OnMediaLocation asOnMediaLocation(const zypp::Pathname &path, unsigned int mediaNr) const
ProvideRes(ProvideMediaHandle hdl, zypp::ManagedFile file)
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
bool empty() const
Test for an empty path.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
const std::string & asString() const
String representation.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
const std::vector< OriginEndpoint > & mirrors() const
zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin) const
static bool schemeIsVolatile(const std::string &scheme_r)
cd dvd
Base class for reference counted objects.
int unlink(const Pathname &path)
Like 'unlink'.
static expected success(ConsParams &&...params)
IMPL_PTR_TYPE(AttachedMediaInfo)
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
expected< Res > provide(const zypp::MirroredOrigin &origin, const ProvideFileSpec &request)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
expected< MediaHandle > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
Base class for Exception.
expected< zypp::CheckSum > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Wrapper for const correct access via Smart pointer types.
A "struct mntent" like mount entry structure, but using std::strings.
unsigned int devMajor() const
Wrapper class for ::stat/::lstat.
expected< LazyMediaHandle > prepareMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
void setAuthority(OriginEndpoint newAuthority)
ResultType and_then(const expected< T, E > &exp, Function &&f)
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
expected< zypp::ManagedFile > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
const OriginEndpoint & authority() const
Represents a single, configurable network endpoint, combining a URL with specific access settings...
expected< MediaHandle > attachMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
bool checkExistsOnly() const
const zypp::Pathname file() const
void releaseMedium(const AttachedMediaInfo *ptr)