16 #include <zypp-media/ng/ProvideSpec> 33 const std::optional<zypp::Pathname> &
rootPath()
const;
34 MediaSyncFacadeRef
parent()
const;
43 void unref_to(
unsigned int)
const override;
57 , _origin(
std::move( origin ) )
58 , _spec(
std::move( mediaSpec ))
59 , _parent(
std::move( parentRef ))
60 , _localPath( locPath )
103 _parent->releaseMedium (
this );
117 return _data->parent();
122 return _data.get() !=
nullptr;
128 if ( !
_data )
return invalidHandle;
129 return _data->origin().authority().url();
134 static std::optional<zypp::Pathname> invalidPath;
137 return _data->rootPath();
146 : _res(
std::move(file) )
147 , _provideHandle(
std::move (hdl) )
159 if ( !handlerType ) {
160 ERR <<
"Authority URL: " << origin.
authority() <<
" is not supported!" << std::endl;
165 for (
const auto &mirror : origin.
mirrors() ) {
168 WAR <<
"URL: " << mirror <<
" is not supported, ignoring!" << std::endl;
171 if ( handlerType == *s) {
172 sanitized.addMirror(mirror);
174 WAR <<
"URL: " << mirror <<
" has different handler type than the authority URL: "<< origin.
authority() <<
", ignoring!" << std::endl;
191 if ( !sanitizedOrigin.
isValid() )
195 for (
auto &ep : sanitizedOrigin )
201 return medium->isSameMedium( sanitizedOrigin, request );
210 std::optional<zypp::media::MediaAccessId> attachId;
218 attachId = mgr.
open( sanitizedOrigin );
227 auto locPath = mgr.
localPath( *attachId,
"/" );
228 auto attachInfo = AttachedSyncMediaInfo_Ptr(
new AttachedSyncMediaInfo( shared_this<MediaSyncFacade>(), *attachId, std::move(sanitizedOrigin), request, locPath ) );
254 unsigned int devindex = 0;
256 std::vector<std::string> devices;
259 std::optional<std::string> currentlyUsed;
260 if ( devices.size() ) currentlyUsed = devices[devindex];
265 devices.erase(
std::remove_if( devices.begin (), devices.end(), [&](
const std::string &dev) {
273 if ( !devices.size () ) {
275 MIL <<
"No free device available, return jammed and try again later ( hopefully) " << std::endl;
276 if ( attachId ) mgr.
close ( *attachId );
281 bool foundCurrent =
false;
282 if ( currentlyUsed ) {
283 for (
unsigned int i = 0; i < devices.size(); i++ ) {
284 if ( devices[i] == *currentlyUsed ) {
292 if ( !foundCurrent ){
299 user = report->requestMedia (
309 MIL <<
"ProvideFile exception caught, callback answer: " << user << std::endl;
313 DBG <<
"Aborting" << std::endl;
314 if ( attachId ) mgr.
close ( *attachId );
315 zypp::AbortRequestException aexcp(
"Aborting requested by user");
316 aexcp.remember(excp);
320 DBG <<
"Skipping" << std::endl;
321 if ( attachId ) mgr.
close ( *attachId );
322 zypp::SkipRequestException nexcp(
"User-requested skipping of a file");
323 nexcp.remember(excp);
327 DBG <<
"Eject: try to release" << std::endl;
332 mgr.
release (*attachId, devindex < devices.size() ? devices[devindex] :
"");
343 DBG <<
"Going to try again" << std::endl;
347 mgr.
close(*attachId);
352 if ( sanitizedOrigin.
authority().
url() != effectiveUrl ) {
362 DBG <<
"Don't know, let's ABORT" << std::endl;
363 if ( attachId ) mgr.
close ( *attachId );
370 if ( attachId ) mgr.
close ( *attachId );
374 if ( attachId ) mgr.
close ( *attachId );
385 WAR <<
"Releasing zyppng::MediaSyncFacade with still valid MediaHandles, this is a bug!" << std::endl;
392 if ( !sanitizedOrigin.isValid() )
408 MIL <<
"Attaching lazy medium with label: [" << lazyHandle.
spec().
label() <<
"]" << std::endl;
424 std::optional<expected<MediaSyncFacade::Res>> lastErr;
447 zypp::Url url( origin.authority().url() );
449 url.setPathName (
"/");
462 const auto &handleInfo = attachHandle.
info();
466 if ( !mgr.
doesFileExist ( handleInfo.mediaId (), fileName ) ) {
481 if ( handleInfo.url().schemeIsDownloading() )
499 |
and_then([weakMe = weak_this<MediaSyncFacade>(), fName = fileName, req = request ](
MediaHandle handle ){
500 auto me = weakMe.lock();
503 return me->provide( handle, fName, req);
524 if ( !sourcePi.isExist() ) {
527 if ( !sourcePi.isFile () )
563 ERR <<
"Releasing unknown medium " << ptr->
mediaId () <<
" should not happen";
IMPL_PTR_TYPE(AttachedSyncMediaInfo)
const zypp::Url & url() const
ZYPP_IMPL_PRIVATE_CONSTR(Context)
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
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
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)
void remove_if(LockSet &lockset_r, TPredicate pred_r)
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Base class for Exception.
bool any_of(const Container &c, Fnc &&cb)
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.
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.
const OriginEndpoint & authority() const
Represents a single, configurable network endpoint, combining a URL with specific access settings...
bool checkExistsOnly() const
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.