26#include <zypp-media/Mount>
34#define NONREMOTE_DIRECTORY_YAST 1
56 std::vector<MediaUrl> urls_r,
58 Pathname urlpath_below_attachpoint_r,
59 const bool does_download_r )
72 if ( !real_attach_point.
empty() ) {
86 || (
_url.url().getScheme() !=
"file"
87 &&
_url.url().getScheme() !=
"dir"
90 ERR <<
"Provided attach point is not a absolute directory: "
148 INT <<
"MediaHandler deleted with media attached." << endl;
152 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
162 int res = recursive_rmdir( path );
164 MIL <<
"Deleted default attach point " << path << endl;
166 ERR <<
"Failed to Delete default attach point " << path
167 <<
" errno(" << res <<
")" << endl;
173 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
287 if( attach_prefix.
empty())
289 MIL <<
"Resetting to built-in attach point prefixes."
297 MIL <<
"Setting user defined attach point prefix: "
298 << attach_prefix << std::endl;
320 if ( ! aroot.
empty() )
324 if ( apoint.
empty() )
327 if ( ! aroot.
empty() )
331 if ( apoint.
empty() )
334 if ( ! aroot.
empty() )
338 if ( apoint.
empty() )
341 except.addHistory(
_(
"Create attach point: Can't find a writable directory to create an attach point") );
345 MIL <<
"Created default attach point " << apoint << std::endl;
355 ERR <<
"Create attach point: invalid attach root: '"
356 << attach_root <<
"'" << std::endl;
362 DBG <<
"Create attach point: attach root is not a writable directory: '"
363 << attach_root <<
"'" << std::endl;
367 static bool cleanup_once(
true );
370 cleanup_once =
false;
371 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
372 std::list<std::string> entries;
374 for (
const std::string & entry : entries )
378 PathInfo sdir( attach_root + entry );
380 && sdir.
dev() == adir.
dev()
383 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
393 if ( ! apoint.
empty() )
399 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
404 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
437 if( ref && !ref->type.empty() && !ref->name.empty())
483 bool _isAttached =
false;
498 DBG <<
"Mount table changed - rereading it" << std::endl;
500 DBG <<
"Forced check of the mount table" << std::endl;
503 for_( e, entries.begin(), entries.end() )
508 bool is_device = e->isBlockDevice();
513 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
518 DBG <<
"Found media device "
520 <<
" in the mount table as " << e->src << std::endl;
534 if ( matchMountFs && e->type != ref.
mediaSource->type )
537 matchMountFs =
false;
538 else if ( ( e->type ==
"cifs" || e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
539 matchMountFs =
false;
558 DBG <<
"Found media name "
560 <<
" in the mount table as " << e->src << std::endl;
569 DBG <<
"Found bound media "
571 <<
" in the mount table as " << e->src << std::endl;
586 DBG <<
"Found bound media "
588 <<
" in the mount table as " << e->src << std::endl;
597 MIL <<
"Looking for " << ref << endl;
598 if( entries.empty() )
600 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
604 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
608 ERR <<
"Attached media not in mount table any more - forcing reset!"
615 WAR <<
"Attached media not in mount table ..." << std::endl;
656 MIL <<
"Attached: " << *
this << endl;
669 if ( _localRoot.
empty() )
695 MIL <<
"Disconnected: " << *
this << endl;
709 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'"
711 if ( !ejectDev.empty() )
716 DBG <<
"Request to release attached media "
741 else if( !ejectDev.empty() ) {
754 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
773 DBG <<
"Releasing shared media reference only" << std::endl;
777 MIL <<
"Released: " << *
this << endl;
792 MountEntries::const_iterator e;
793 for( e = entries.begin(); e != entries.end(); ++e)
795 bool is_device =
false;
799 dev_info(e->src) && dev_info.
isBlk())
804 if( is_device && ref->maj_nr)
806 std::string mtype(matchMountFs ? e->type : ref->type);
809 if( ref->equals(
media) && e->type !=
"subfs")
811 DBG <<
"Forcing release of media device "
813 <<
" in the mount table as "
814 << e->src << std::endl;
826 if(!is_device && !ref->maj_nr)
828 std::string mtype(matchMountFs ? e->type : ref->type);
830 if( ref->equals(
media))
832 DBG <<
"Forcing release of media name "
834 <<
" in the mount table as "
835 << e->src << std::endl;
863 ERR <<
"Attach point '" << apoint <<
"' is not absolute"
869 ERR <<
"Attach point '" << apoint <<
"' is not allowed"
877 ERR <<
"Attach point '" << apoint <<
"' is not a directory"
886 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory"
895 char *atemp = ::strdup( apath.
asString().c_str());
898 (atest=::mkdtemp(atemp)) == NULL)
903 ERR <<
"Attach point '" << ainfo.
path()
904 <<
"' is not a writeable directory" << std::endl;
907 else if( atest != NULL)
962 INT <<
"Media not_attached on provideFileCopy(" << srcFile
963 <<
"," << targetFilename <<
")" << endl;
968 DBG <<
"provideFileCopy(" << srcFile <<
"," << targetFilename <<
")" << endl;
974 INT <<
"Error: Not attached on provideFile(" << file <<
")" << endl;
979 DBG <<
"provideFile(" << file <<
")" << endl;
994 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
999 MIL <<
"provideDir(" << dirname <<
")" << endl;
1013 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1018 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1037 unlink( info.
path() );
1038 }
else if ( info.
isDir() ) {
1040 recursive_rmdir( info.
path() );
1042 clean_dir( info.
path() );
1056 const Pathname & dirname,
bool dots )
const
1061 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1066 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1078 const Pathname & dirname,
bool dots )
const
1083 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1088 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1103 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1107 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1117 const Pathname & dirname,
bool dots )
const
1125 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1126 retlist.push_back( it->name );
1137 const Pathname & dirname,
bool dots )
const
1144 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1149 ERR <<
"Unable to load '" <<
localPath( dirFile.filename() ) <<
"'" << endl;
1155 while( getline( dir, line ) ) {
1156 if ( line.empty() )
continue;
1157 if ( line ==
"directory.yast" )
continue;
1162 if ( *line.rbegin() ==
'/' ) {
1163 line.erase( line.end()-1 );
1168 if ( line ==
"." || line ==
".." )
continue;
1170 if ( *line.begin() ==
'.' )
continue;
1186 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1224 if( info.
isDir() ) {
1244 const Pathname & dirname,
bool dots )
const
1247 if( ! info.
isDir() ) {
1251#if NONREMOTE_DIRECTORY_YAST
1261 int res = readdir( retlist, info.
path(), dots );
1265#if NONREMOTE_DIRECTORY_YAST
1271#if NONREMOTE_DIRECTORY_YAST
1288 const Pathname & dirname,
bool dots )
const
1291 if( ! info.
isDir() ) {
1295#if NONREMOTE_DIRECTORY_YAST
1305 int res = readdir( retlist, info.
path(), dots );
1309#if NONREMOTE_DIRECTORY_YAST
1314#if NONREMOTE_DIRECTORY_YAST
1331 if( info.
isDir() ) {
1343 unsigned int & index)
const
1346 if (!devices.empty())
1350 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.
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.