26#include <zypp-media/Mount>
34#define NONREMOTE_DIRECTORY_YAST 1
57 Pathname urlpath_below_attachpoint_r,
58 const bool does_download_r )
70 if ( !real_attach_point.
empty() ) {
88 ERR <<
"Provided attach point is not a absolute directory: "
146 INT <<
"MediaHandler deleted with media attached." << endl;
150 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
160 int res = recursive_rmdir( path );
162 MIL <<
"Deleted default attach point " << path << endl;
164 ERR <<
"Failed to Delete default attach point " << path
165 <<
" errno(" << res <<
")" << endl;
171 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
285 if( attach_prefix.
empty())
287 MIL <<
"Resetting to built-in attach point prefixes."
295 MIL <<
"Setting user defined attach point prefix: "
296 << attach_prefix << std::endl;
318 if ( ! aroot.
empty() )
322 if ( apoint.
empty() )
325 if ( ! aroot.
empty() )
329 if ( apoint.
empty() )
332 if ( ! aroot.
empty() )
336 if ( apoint.
empty() )
339 except.addHistory(
_(
"Create attach point: Can't find a writable directory to create an attach point") );
343 MIL <<
"Created default attach point " << apoint << std::endl;
353 ERR <<
"Create attach point: invalid attach root: '"
354 << attach_root <<
"'" << std::endl;
360 DBG <<
"Create attach point: attach root is not a writable directory: '"
361 << attach_root <<
"'" << std::endl;
365 static bool cleanup_once(
true );
368 cleanup_once =
false;
369 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
370 std::list<std::string> entries;
372 for (
const std::string & entry : entries )
376 PathInfo sdir( attach_root + entry );
378 && sdir.
dev() == adir.
dev()
381 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
391 if ( ! apoint.
empty() )
397 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
402 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
435 if( ref && !ref->type.empty() && !ref->name.empty())
481 bool _isAttached =
false;
496 DBG <<
"Mount table changed - rereading it" << std::endl;
498 DBG <<
"Forced check of the mount table" << std::endl;
501 for_( e, entries.begin(), entries.end() )
506 bool is_device = e->isBlockDevice();
511 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
516 DBG <<
"Found media device "
518 <<
" in the mount table as " << e->src << std::endl;
532 if ( matchMountFs && e->type != ref.
mediaSource->type )
535 matchMountFs =
false;
536 else if ( ( e->type ==
"cifs" || e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
537 matchMountFs =
false;
556 DBG <<
"Found media name "
558 <<
" in the mount table as " << e->src << std::endl;
567 DBG <<
"Found bound media "
569 <<
" in the mount table as " << e->src << std::endl;
584 DBG <<
"Found bound media "
586 <<
" in the mount table as " << e->src << std::endl;
595 MIL <<
"Looking for " << ref << endl;
596 if( entries.empty() )
598 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
602 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
606 ERR <<
"Attached media not in mount table any more - forcing reset!"
613 WAR <<
"Attached media not in mount table ..." << std::endl;
654 MIL <<
"Attached: " << *
this << endl;
667 if ( _localRoot.
empty() )
693 MIL <<
"Disconnected: " << *
this << endl;
707 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'"
709 if ( !ejectDev.empty() )
714 DBG <<
"Request to release attached media "
739 else if( !ejectDev.empty() ) {
752 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
771 DBG <<
"Releasing shared media reference only" << std::endl;
775 MIL <<
"Released: " << *
this << endl;
790 MountEntries::const_iterator e;
791 for( e = entries.begin(); e != entries.end(); ++e)
793 bool is_device =
false;
797 dev_info(e->src) && dev_info.
isBlk())
802 if( is_device && ref->maj_nr)
804 std::string mtype(matchMountFs ? e->type : ref->type);
807 if( ref->equals(
media) && e->type !=
"subfs")
809 DBG <<
"Forcing release of media device "
811 <<
" in the mount table as "
812 << e->src << std::endl;
824 if(!is_device && !ref->maj_nr)
826 std::string mtype(matchMountFs ? e->type : ref->type);
828 if( ref->equals(
media))
830 DBG <<
"Forcing release of media name "
832 <<
" in the mount table as "
833 << e->src << std::endl;
861 ERR <<
"Attach point '" << apoint <<
"' is not absolute"
867 ERR <<
"Attach point '" << apoint <<
"' is not allowed"
875 ERR <<
"Attach point '" << apoint <<
"' is not a directory"
884 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory"
893 char *atemp = ::strdup( apath.
asString().c_str());
896 (atest=::mkdtemp(atemp)) == NULL)
901 ERR <<
"Attach point '" << ainfo.
path()
902 <<
"' is not a writeable directory" << std::endl;
905 else if( atest != NULL)
960 INT <<
"Media not_attached on provideFileCopy(" << srcFile
961 <<
"," << targetFilename <<
")" << endl;
966 DBG <<
"provideFileCopy(" << srcFile <<
"," << targetFilename <<
")" << endl;
972 INT <<
"Error: Not attached on provideFile(" << file <<
")" << endl;
977 DBG <<
"provideFile(" << file <<
")" << endl;
992 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
997 MIL <<
"provideDir(" << dirname <<
")" << endl;
1011 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1016 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1035 unlink( info.
path() );
1036 }
else if ( info.
isDir() ) {
1038 recursive_rmdir( info.
path() );
1040 clean_dir( info.
path() );
1054 const Pathname & dirname,
bool dots )
const
1059 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1064 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1076 const Pathname & dirname,
bool dots )
const
1081 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1086 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1101 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1105 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1115 const Pathname & dirname,
bool dots )
const
1123 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1124 retlist.push_back( it->name );
1135 const Pathname & dirname,
bool dots )
const
1142 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1147 ERR <<
"Unable to load '" <<
localPath( dirFile.filename() ) <<
"'" << endl;
1153 while( getline( dir, line ) ) {
1154 if ( line.empty() )
continue;
1155 if ( line ==
"directory.yast" )
continue;
1160 if ( *line.rbegin() ==
'/' ) {
1161 line.erase( line.end()-1 );
1166 if ( line ==
"." || line ==
".." )
continue;
1168 if ( *line.begin() ==
'.' )
continue;
1184 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1222 if( info.
isDir() ) {
1242 const Pathname & dirname,
bool dots )
const
1245 if( ! info.
isDir() ) {
1249#if NONREMOTE_DIRECTORY_YAST
1259 int res = readdir( retlist, info.
path(), dots );
1263#if NONREMOTE_DIRECTORY_YAST
1269#if NONREMOTE_DIRECTORY_YAST
1286 const Pathname & dirname,
bool dots )
const
1289 if( ! info.
isDir() ) {
1293#if NONREMOTE_DIRECTORY_YAST
1303 int res = readdir( retlist, info.
path(), dots );
1307#if NONREMOTE_DIRECTORY_YAST
1312#if NONREMOTE_DIRECTORY_YAST
1329 if( info.
isDir() ) {
1341 unsigned int & index)
const
1344 if (!devices.empty())
1348 DBG <<
"No devices for this medium" << endl;
static const ValueType month
static Date now()
Return the current time.
Base class for Exception.
void remember(const Exception &old_r)
Store an other Exception as history.
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Pathname download_mediaMountdir() const
Path where media are preferably mounted or downloaded.
static ZConfig & instance()
Singleton ctor.
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
unsigned int devMinor() const
bool isExist() const
Return whether valid stat info exists.
unsigned int devMajor() const
bool absolute() const
Test for an absolute path.
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.
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Provide a new empty temporary directory and recursively delete it when no longer needed.
static const Pathname & defaultLocation()
bool autoCleanup() const
Whether path is valid and deleted when the last reference drops.
String related utilities and Regular expression matching.
FileType
File type information.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
std::list< DirEntry > DirContent
Returned by readdir.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int is_empty_dir(const Pathname &path_r)
Check if the specified directory is empty.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
void swap(RW_pointer &rhs) noexcept
Listentry returned by readdir.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#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.