17#include <zypp-media/MediaException>
21#include <zypp-media/Mount>
23#include <zypp/base/String.h>
24#include <zypp/base/Logger.h>
25#include <zypp/Pathname.h>
26#include <zypp/PathInfo.h>
41 std::ostream &
operator<<( std::ostream &
str,
const ManagedMedia & obj );
56 ManagedMedia( ManagedMedia &&m )
62 static ManagedMedia makeManagedMedia (
const Url &o_url,
const Pathname &preferred_attach_point,
const MediaVerifierRef &v )
66 ERR <<
"Failed to create media handler" << std::endl;
67 ZYPP_THROW( MediaSystemException(o_url,
"Failed to create media handler"));
69 return ManagedMedia( std::move(handler), v );
72 ManagedMedia &operator= ( ManagedMedia &&other ) =
default;
74 operator bool ()
const {
75 return ( _handler ?
true : false );
78 inline MediaHandler &handler() {
80 ZYPP_THROW(MediaNotOpenException(
"Accessing ManagedMedia after it was closed"));
84 inline const MediaHandler &handler()
const {
86 ZYPP_THROW(MediaNotOpenException(
"Accessing ManagedMedia after it was closed"));
90 std::ostream &
dumpOn( std::ostream &
str )
const {
92 return str <<
"ManagedMedia( closed )";
108 catch (
const MediaException & excpt_r)
111 WAR <<
"Close: " << *
this <<
" (" << excpt_r <<
")" << std::endl;
114 MIL <<
"Close: " << *
this <<
" (OK)" << std::endl;
120 if( !handler().isAttached())
122 DBG <<
"checkAttached(" <<
id <<
") not attached" << std::endl;
136 const auto &hdl = handler();
142 media::MediaNotDesiredException newEx ( hdl.url() );
149 DBG <<
"checkDesired(" <<
id <<
"): not desired (report by " <<
verifier->info() <<
")" << std::endl;
150 ZYPP_THROW( MediaNotDesiredException( hdl.url() ) );
153 DBG <<
"checkDesired(" <<
id <<
"): desired (report by " <<
verifier->info() <<
")" << std::endl;
155 DBG <<
"checkDesired(" <<
id <<
"): desired (cached)" << std::endl;
173 std::ostream &
operator<<( std::ostream &
str,
const ManagedMedia & obj ) {
174 return obj.dumpOn(
str );
178 typedef std::map<MediaAccessId, ManagedMedia> ManagedMediaMap;
189 return std::string(
typeid((*
this)).name());
197 return std::string(
"zypp::media::NoVerifier");
220 ManagedMediaMap::iterator
it;
227 if(
it->second &&
it->second.handler().dependsOnParent() )
232 it->second.handler().resetParentId();
259 inline ManagedMedia &
278 static inline MountEntries
316 m_impl->mediaMap.insert( std::make_pair( nextId, std::move(
tmp) ) );
319 DBG <<
"Opened new media access using id " << nextId
320 <<
" to " << url.
asString() << std::endl;
338 ManagedMediaMap::iterator
m(
m_impl->mediaMap.begin());
339 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
341 if(
m->second.handler().dependsOnParent(
accessId,
true))
344 m->second.handler().url().asString()
349 DBG <<
"Close to access handler using id "
350 <<
accessId <<
" requested" << std::endl;
363 return it !=
m_impl->mediaMap.end();
372 return ref.handler().protocol();
381 return ref.handler().downloads();
390 return ref.handler().url();
406 DBG <<
"MediaVerifier change: id=" <<
accessId <<
", verifier="
420 DBG <<
"MediaVerifier change: id=" <<
accessId <<
", verifier="
435 auto &
hdl = ref.handler();
437 DBG <<
"attach(id=" <<
accessId <<
")" << std::endl;
450 if (!
hdl.hasMoreDevices())
453 if (
hdl.isAttached())
457 MIL <<
"checkDesired(" <<
accessId <<
") of first device failed,"
458 " going to try others with attach(true)" << std::endl;
460 while (
hdl.hasMoreDevices())
473 if (!
hdl.hasMoreDevices())
475 MIL <<
"No desired media found after trying all detected devices." << std::endl;
480 DBG <<
"Skipping " << media.
mediaSource->asString() <<
": not desired media." << std::endl;
488 if (!
hdl.hasMoreDevices())
492 DBG <<
"Skipping " << media.
mediaSource->asString() <<
" because of exception thrown by attach(true)" << std::endl;
494 if (
hdl.isAttached())
hdl.release();
508 DBG <<
")" << std::endl;
518 ManagedMediaMap::iterator
m(
m_impl->mediaMap.begin());
519 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
521 auto &
hdl =
m->second.handler();
526 DBG <<
"Forcing release of handler depending on access id "
528 m->second.desired =
false;
546 MIL <<
"Releasing all attached media" << std::endl;
551 if (
hdl.isAttached() ) {
552 DBG <<
"Releasing media id " <<
mId_r << std::endl;
557 DBG <<
"Media id " <<
mId_r <<
" not attached " << std::endl;
562 ERR <<
"Failed to release media id " <<
mId_r << std::endl;
576 MIL <<
"Exit" << std::endl;
585 ref.handler().disconnect();
594 return ref.handler().isAttached();
602 return ref.handler().isSharedMedia();
611 if( !ref.handler().isAttached())
618 ref.desired = ref.verifier->isDesiredMedia( ref.handler() );
626 << (ref.desired ?
"" :
"not ")
627 <<
"desired (report by "
628 << ref.verifier->info() <<
")" << std::endl;
644 if( ref.handler().isAttached())
647 desired =
v->isDesiredMedia( ref.handler() );
656 <<
"desired (report by "
657 <<
v->info() <<
")" << std::endl;
675 path = ref.handler().localRoot();
687 path = ref.handler().localPath(pathname);
694 const ByteCount &expectedFileSize )
const
724 ref.handler().provideFile( file );
736 ref.deltafile = filename;
745 ref.handler().precacheFiles( files );
757 ref.handler().provideDir(dirname);
769 ref.handler().provideDirTree(dirname);
781 ref.handler().releaseFile(filename);
793 ref.handler().releaseDir(dirname);
806 ref.handler().releasePath(pathname);
812 std::list<std::string> &
retlist,
848 return ref.handler().doesFileExist(filename);
854 std::vector<std::string> &
devices,
855 unsigned int & index)
const
858 return ref.handler().getDetectedDevices(
devices, index);
888 ManagedMediaMap::const_iterator
m(
m_impl->mediaMap.begin());
889 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
892 if(
ret.mediaSource &&
ret.attachPoint)
894 std::string
mnt(
ret.attachPoint->path.asString());
903 if(
mnt.size() >
our.size() &&
904 mnt.at(
our.size()) ==
'/' &&
920 MountEntries entries(
m_impl->getMountEntries());
921 MountEntries::const_iterator
e;
922 for(
e = entries.begin();
e != entries.end(); ++
e)
933 if(
mnt.size() >
our.size() &&
934 mnt.at(
our.size()) ==
'/' &&
952 return ref.handler().attachedMedia();
959 if( !media || media->type.empty())
962 ManagedMediaMap::const_iterator
m(
m_impl->mediaMap.begin());
963 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
965 if( !
m->second.handler().isAttached())
969 if(
ret.mediaSource &&
ret.mediaSource->equals( *media))
979 if( !media || media->type.empty())
982 ManagedMediaMap::iterator
m(
m_impl->mediaMap.begin());
983 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
985 if( !
m->second.handler().isAttached())
989 if(
ret.mediaSource &&
ret.mediaSource->equals( *media))
991 m->second.handler().release();
992 m->second.desired =
false;
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void reset()
Reset to default Ctor values.
void swap(AutoDispose &rhs)
Exchange the contents of two AutoDispose objects.
Store and operate with byte count.
Base class for Exception.
std::string getScheme() const
Returns the scheme name of the URL.
std::string asString() const
Returns a default string representation of the Url object.
Wrapper class for stat/lstat.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
String related utilities and Regular expression matching.
std::list< DirEntry > DirContent
Returned by readdir.
std::string numstring(char n, int w=0)
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Wrapper for const correct access via Smart pointer types.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.