13#include <zypp-media/ng/MediaVerifier>
14#include <zypp-media/MediaException>
19#undef ZYPP_BASE_LOGGER_LOGGROUP
20#define ZYPP_BASE_LOGGER_LOGGROUP "zyppng::worker::DeviceDriver"
37 const auto &val =
i->second;
38 MIL <<
"Got attachpoint from controller: " << val << std::endl;
72 if (
i->use_count() == 1 && !(*i)->_mountPoint.empty() ) {
73 MIL <<
"Unmounting device " << (*i)->_name <<
" since its not used anymore" << std::endl;
75 if ( (*i)->_ephemeral ) {
109 if ( (*i)->_ephemeral ) {
132 ERR <<
"Failed to unmount device: " << dev.
_name << std::endl;
151 MIL <<
"Attach root is empty" << std::endl;
167 if (
p.isExist() &&
p.isDir() )
185 if ( !
pi.isExist() ) {
189 excpt.addHistory(
verifier->expectedAsUserString( mediaNr ) );
192 if ( !
pi.isFile() ) {
196 excpt.addHistory(
verifier->expectedAsUserString( mediaNr ) );
214 ERR <<
"Create attach point: invalid attach root: '"
221 DBG <<
"Create attach point: attach root is not a writable directory: '"
230 DBG <<
"Look for orphaned attach points in " <<
adir << std::endl;
231 std::list<std::string> entries;
233 for (
const std::string &
entry : entries )
242 DBG <<
"Remove orphaned attach point " <<
sdir << std::endl;
254 tmpdir.autoCleanup(
false );
258 ERR <<
"Unable to resolve real path for attach point " <<
tmpdir << std::endl;
263 ERR <<
"Unable to create attach point below " <<
attach_root << std::endl;
275 MIL <<
"Deleted default attach point " <<
attachRoot << std::endl;
277 ERR <<
"Failed to Delete default attach point " <<
attachRoot
278 <<
" errno(" <<
res <<
")" << std::endl;
285 bool isAttached =
false;
293 DBG <<
"Mount table changed - rereading it" << std::endl;
295 DBG <<
"Forced check of the mount table" << std::endl;
318 if(
entry.isBlockDevice() ) {
321 DBG <<
"Found device "
323 <<
" in the mount table as " <<
entry.src << std::endl;
334 if( !entry.isBlockDevice() ) {
335 if ( std::find( fst.begin(), fst.end(), entry.type ) != fst.end() ) {
336 if ( srcdev == entry.src ) {
337 DBG <<
"Found media mount"
338 <<
" in the mount table as " << entry.src << std::endl;
350 if( !entry.isBlockDevice() ) {
351 if ( srcdev == entry.src ) {
352 DBG <<
"Found bound media "
353 <<
" in the mount table as " << entry.src << std::endl;
375 if ( !
e.historyEmpty() ) {
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
static const ValueType month
static Date now()
Return the current time.
Base class for Exception.
Wrapper class for stat/lstat.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
Pathname realpath() const
Returns this path as the absolute canonical pathname.
Provide a new empty temporary directory and recursively delete it when no longer needed.
static expected success(ConsParams &&...params)
zypp::Pathname attachRoot() const
zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const
virtual zyppng::expected< WorkerCaps > initialize(const zyppng::worker::Configuration &conf)
static const std::function< bool(const zypp::media::MountEntry &) bindMountPredicate)(const std::string &src)
bool checkAttached(const zypp::Pathname &mountPoint, const std::function< bool(const zypp::media::MountEntry &)> predicate)
static const std::function< bool(const zypp::media::MountEntry &) fstypePredicate)(const std::string &src, const std::vector< std::string > &fstypes)
ProvideWorkerWeakRef _parentWorker
bool detachMedia(const std::string &attachId)
DeviceDriver(WorkerCaps::WorkerType wType)
zypp::Pathname _attachRoot
virtual bool isVolatile() const
static const std::function< bool(const zypp::media::MountEntry &) devicePredicate)(unsigned int majNr, unsigned int minNr)
void setProvider(ProvideWorkerWeakRef workerRef)
zyppng::expected< void > isDesiredMedium(const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr=1)
WorkerCaps::WorkerType _wType
virtual void detectDevices()
std::unordered_map< std::string, AttachedMedia > & attachedMedia()
std::vector< std::shared_ptr< Device > > & knownDevices()
const zyppng::worker::Configuration & config() const
virtual void immediateShutdown()
void removeAttachPoint(const zypp::Pathname &attach_pt) const
std::vector< std::shared_ptr< Device > > _sysDevs
ProviderConfiguration _config
std::unordered_map< std::string, AttachedMedia > _attachedMedia
ProvideWorkerRef parentWorker() const
void releaseIdleDevices()
void setAttachRoot(const zypp::Pathname &root)
virtual void unmountDevice(Device &dev)
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
std::string asUserString(VendorSupportOption opt)
converts the support option to a name intended to be printed to the user.
constexpr std::string_view History("history")
constexpr std::string_view ATTACH_POINT("zconfig://media/AttachPoint")
A "struct mntent" like mount entry structure, but using std::strings.
AttachError(const uint code, const std::string &reason, const bool transient, const HeaderValueMap &extra={})
std::string _name
Path of the device node or URL for e.g. nfs devices.
zypp::Pathname _mountPoint
Mountpoint of the device, if empty dev is not mounted.
#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.