18#include <zypp-media/MediaException>
22#include <zypp-media/Mount>
42 std::ostream &
operator<<( std::ostream &
str,
const ManagedMedia & obj );
57 ManagedMedia(
const ManagedMedia &) =
delete;
58 ManagedMedia &operator=(
const ManagedMedia &) =
delete;
60 ManagedMedia(ManagedMedia &&m) noexcept
64 static ManagedMedia makeManagedMedia (
const Url &o_url,
const Pathname &preferred_attach_point,
const MediaVerifierRef &v )
68 ERR <<
"Failed to create media handler" << std::endl;
69 ZYPP_THROW( MediaSystemException(o_url,
"Failed to create media handler"));
71 return ManagedMedia( std::move(handler), v );
74 ManagedMedia &operator= ( ManagedMedia &&other ) =
default;
76 operator bool ()
const {
77 return ( _handler ?
true : false );
80 inline MediaHandler &handler() {
82 ZYPP_THROW(MediaNotOpenException(
"Accessing ManagedMedia after it was closed"));
86 inline const MediaHandler &handler()
const {
88 ZYPP_THROW(MediaNotOpenException(
"Accessing ManagedMedia after it was closed"));
92 std::ostream &
dumpOn( std::ostream &
str )
const {
94 return str <<
"ManagedMedia( closed )";
110 catch (
const MediaException & excpt_r)
113 WAR <<
"Close: " << *
this <<
" (" << excpt_r <<
")" << std::endl;
116 MIL <<
"Close: " << *
this <<
" (OK)" << std::endl;
122 if( !handler().isAttached())
124 DBG <<
"checkAttached(" <<
id <<
") not attached" << std::endl;
138 const auto &hdl = handler();
144 media::MediaNotDesiredException newEx ( hdl.url() );
151 DBG <<
"checkDesired(" <<
id <<
"): not desired (report by " <<
verifier->info() <<
")" << std::endl;
152 ZYPP_THROW( MediaNotDesiredException( hdl.url() ) );
155 DBG <<
"checkDesired(" <<
id <<
"): desired (report by " <<
verifier->info() <<
")" << std::endl;
157 DBG <<
"checkDesired(" <<
id <<
"): desired (cached)" << std::endl;
175 std::ostream &
operator<<( std::ostream &
str,
const ManagedMedia & obj ) {
176 return obj.dumpOn(
str );
180 using ManagedMediaMap = std::map<MediaAccessId, ManagedMedia>;
191 return std::string(
typeid((*
this)).name());
199 return std::string(
"zypp::media::NoVerifier");
228 ManagedMediaMap::iterator
it;
235 if(
it->second &&
it->second.handler().dependsOnParent() )
240 it->second.handler().resetParentId();
267 inline ManagedMedia &
286 static inline MountEntries
324 m_impl->mediaMap.insert( std::make_pair( nextId, std::move(
tmp) ) );
327 DBG <<
"Opened new media access using id " << nextId
328 <<
" to " << url.
asString() << std::endl;
346 ManagedMediaMap::iterator
m(
m_impl->mediaMap.begin());
347 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
349 if(
m->second.handler().dependsOnParent(
accessId,
true))
352 m->second.handler().url().asString()
357 DBG <<
"Close to access handler using id "
358 <<
accessId <<
" requested" << std::endl;
371 return it !=
m_impl->mediaMap.end();
380 return ref.handler().protocol();
389 return ref.handler().downloads();
398 return ref.handler().url();
414 DBG <<
"MediaVerifier change: id=" <<
accessId <<
", verifier="
428 DBG <<
"MediaVerifier change: id=" <<
accessId <<
", verifier="
443 auto &
hdl = ref.handler();
445 DBG <<
"attach(id=" <<
accessId <<
")" << std::endl;
458 if (!
hdl.hasMoreDevices())
461 if (
hdl.isAttached())
465 MIL <<
"checkDesired(" <<
accessId <<
") of first device failed,"
466 " going to try others with attach(true)" << std::endl;
468 while (
hdl.hasMoreDevices())
481 if (!
hdl.hasMoreDevices())
483 MIL <<
"No desired media found after trying all detected devices." << std::endl;
488 DBG <<
"Skipping " << media.
mediaSource->asString() <<
": not desired media." << std::endl;
496 if (!
hdl.hasMoreDevices())
500 DBG <<
"Skipping " << media.
mediaSource->asString() <<
" because of exception thrown by attach(true)" << std::endl;
502 if (
hdl.isAttached())
hdl.release();
516 DBG <<
")" << std::endl;
526 ManagedMediaMap::iterator
m(
m_impl->mediaMap.begin());
527 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
529 auto &
hdl =
m->second.handler();
534 DBG <<
"Forcing release of handler depending on access id "
536 m->second.desired =
false;
554 MIL <<
"Releasing all attached media" << std::endl;
559 if (
hdl.isAttached() ) {
560 DBG <<
"Releasing media id " <<
mId_r << std::endl;
565 DBG <<
"Media id " <<
mId_r <<
" not attached " << std::endl;
570 ERR <<
"Failed to release media id " <<
mId_r << std::endl;
584 MIL <<
"Exit" << std::endl;
593 ref.handler().disconnect();
602 return ref.handler().isAttached();
610 return ref.handler().isSharedMedia();
619 if( !ref.handler().isAttached())
626 ref.desired = ref.verifier->isDesiredMedia( ref.handler() );
634 << (ref.desired ?
"" :
"not ")
635 <<
"desired (report by "
636 << ref.verifier->info() <<
")" << std::endl;
652 if( ref.handler().isAttached())
655 desired =
v->isDesiredMedia( ref.handler() );
664 <<
"desired (report by "
665 <<
v->info() <<
")" << std::endl;
683 path = ref.handler().localRoot();
695 path = ref.handler().localPath(pathname);
702 const ByteCount &expectedFileSize )
const
732 ref.handler().provideFile( file );
744 ref.deltafile = filename;
753 ref.handler().precacheFiles( files );
765 ref.handler().provideDir(dirname);
777 ref.handler().provideDirTree(dirname);
789 ref.handler().releaseFile(filename);
801 ref.handler().releaseDir(dirname);
814 ref.handler().releasePath(pathname);
820 std::list<std::string> &
retlist,
856 return ref.handler().doesFileExist(filename);
862 std::vector<std::string> &
devices,
863 unsigned int &
index)
const
866 return ref.handler().getDetectedDevices(
devices,
index);
896 ManagedMediaMap::const_iterator
m(
m_impl->mediaMap.begin());
897 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
900 if(
ret.mediaSource &&
ret.attachPoint)
902 std::string
mnt(
ret.attachPoint->path.asString());
911 if(
mnt.size() >
our.size() &&
912 mnt.at(
our.size()) ==
'/' &&
928 MountEntries entries(
m_impl->getMountEntries());
929 MountEntries::const_iterator
e;
930 for(
e = entries.begin();
e != entries.end(); ++
e)
941 if(
mnt.size() >
our.size() &&
942 mnt.at(
our.size()) ==
'/' &&
960 return ref.handler().attachedMedia();
967 if( !media || media->type.empty())
970 ManagedMediaMap::const_iterator
m(
m_impl->mediaMap.begin());
971 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
973 if( !
m->second.handler().isAttached())
977 if(
ret.mediaSource &&
ret.mediaSource->equals( *media))
987 if( !media || media->type.empty())
990 ManagedMediaMap::iterator
m(
m_impl->mediaMap.begin());
991 for( ;
m !=
m_impl->mediaMap.end(); ++
m)
993 if( !
m->second.handler().isAttached())
997 if(
ret.mediaSource &&
ret.mediaSource->equals( *media))
999 m->second.handler().release();
1000 m->second.desired =
false;
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
void reset()
Reset to default Ctor values.
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.