32 #define NONREMOTE_DIRECTORY_YAST 1
37 Pathname MediaHandler::_attachPrefix(
"");
53 MediaHandler::MediaHandler (
const Url & url_r,
54 const Pathname & attach_point_r,
55 const Pathname & urlpath_below_attachpoint_r,
56 const bool does_download_r )
60 , _relativeRoot( urlpath_below_attachpoint_r)
61 , _does_download( does_download_r )
66 Pathname real_attach_point(
getRealPath(attach_point_r.asString()));
68 if ( !real_attach_point.empty() ) {
73 PathInfo adir( real_attach_point );
84 && !real_attach_point.absolute()) )
86 ERR <<
"Provided attach point is not a absolute directory: "
127 char *ptr = ::realpath(path.c_str(), NULL);
137 char buff[PATH_MAX + 2];
138 memset(buff,
'\0',
sizeof(buff));
139 if( ::realpath(path.c_str(), buff) != NULL)
145 char buff[PATH_MAX + 2];
146 memset(buff,
'\0',
sizeof(buff));
147 if( ::realpath(path.c_str(), buff) != NULL)
159 return zypp::Pathname(
getRealPath(path.asString()));
175 INT <<
"MediaHandler deleted with media attached." << endl;
179 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
191 MIL <<
"Deleted default attach point " << path << endl;
193 ERR <<
"Failed to Delete default attach point " << path
194 <<
" errno(" << res <<
")" << endl;
200 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
314 if( attach_prefix.empty())
316 MIL <<
"Reseting to built-in attach point prefixes."
318 MediaHandler::_attachPrefix = attach_prefix;
324 MIL <<
"Setting user defined attach point prefix: "
325 << attach_prefix << std::endl;
326 MediaHandler::_attachPrefix = attach_prefix;
346 const char * defmounts[] = {
351 Pathname aroot( MediaHandler::_attachPrefix);
357 for (
const char ** def = defmounts; *def && apoint.empty(); ++def ) {
365 if ( aroot.empty() ) {
366 ERR <<
"Create attach point: Can't find a writable directory to create an attach point" << std::endl;
370 if ( !apoint.empty() ) {
371 MIL <<
"Created default attach point " << apoint << std::endl;
381 if( attach_root.empty() || !attach_root.absolute()) {
382 ERR <<
"Create attach point: invalid attach root: '"
383 << attach_root <<
"'" << std::endl;
387 PathInfo adir( attach_root );
388 if( !adir.isDir() || (geteuid() != 0 && !adir.userMayRWX())) {
389 DBG <<
"Create attach point: attach root is not a writable directory: '"
390 << attach_root <<
"'" << std::endl;
394 static bool cleanup_once(
true );
397 cleanup_once =
false;
398 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
399 std::list<std::string> entries;
401 for (
const std::string & entry : entries )
405 PathInfo sdir( attach_root + entry );
407 && sdir.dev() == adir.dev()
410 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
420 if ( ! apoint.empty() )
426 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
431 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
464 if( ref && !ref->type.empty() && !ref->name.empty())
510 bool _isAttached =
false;
525 DBG <<
"Mount table changed - rereading it" << std::endl;
527 DBG <<
"Forced check of the mount table" << std::endl;
530 for_( e, entries.begin(), entries.end() )
532 bool is_device =
false;
536 dev_info(e->src) && dev_info.isBlk())
544 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
545 MediaSource media(mtype, e->src, dev_info.major(), dev_info.minor());
550 DBG <<
"Found media device "
552 <<
" in the mount table as " << e->src << std::endl;
566 if ( matchMountFs && e->type != ref.
mediaSource->type )
569 matchMountFs =
false;
570 else if ( ( e->type ==
"cifs" || e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
571 matchMountFs =
false;
573 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
579 DBG <<
"Found media name "
581 <<
" in the mount table as " << e->src << std::endl;
591 DBG <<
"Found bound media "
593 <<
" in the mount table as " << e->src << std::endl;
604 MIL <<
"Looking for " << ref << endl;
605 if( entries.empty() )
607 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
611 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
615 ERR <<
"Attached media not in mount table any more - forcing reset!"
622 WAR <<
"Attached media not in mount table ..." << std::endl;
663 MIL <<
"Attached: " << *
this << endl;
676 if ( _localRoot.empty() )
683 return _localRoot + pathname.absolutename();
702 MIL <<
"Disconnected: " << *
this << endl;
716 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'"
718 if ( !ejectDev.empty() )
723 DBG <<
"Request to release attached media "
748 else if( !ejectDev.empty() ) {
761 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
780 DBG <<
"Releasing shared media reference only" << std::endl;
784 MIL <<
"Released: " << *
this << endl;
799 MountEntries::const_iterator e;
800 for( e = entries.begin(); e != entries.end(); ++e)
802 bool is_device =
false;
806 dev_info(e->src) && dev_info.isBlk())
811 if( is_device && ref->maj_nr)
813 std::string mtype(matchMountFs ? e->type : ref->type);
814 MediaSource media(mtype, e->src, dev_info.major(), dev_info.minor());
816 if( ref->equals( media) && e->type !=
"subfs")
818 DBG <<
"Forcing release of media device "
820 <<
" in the mount table as "
821 << e->src << std::endl;
833 if(!is_device && !ref->maj_nr)
835 std::string mtype(matchMountFs ? e->type : ref->type);
837 if( ref->equals( media))
839 DBG <<
"Forcing release of media name "
841 <<
" in the mount table as "
842 << e->src << std::endl;
868 if( apoint.empty() || !apoint.absolute())
870 ERR <<
"Attach point '" << apoint <<
"' is not absolute"
876 ERR <<
"Attach point '" << apoint <<
"' is not allowed"
881 PathInfo ainfo(apoint);
884 ERR <<
"Attach point '" << apoint <<
"' is not a directory"
893 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory"
901 Pathname apath(apoint +
"XXXXXX");
902 char *atemp = ::strdup( apath.asString().c_str());
904 if( !ainfo.userMayRWX() || atemp == NULL ||
905 (atest=::mkdtemp(atemp)) == NULL)
910 ERR <<
"Attach point '" << ainfo.path()
911 <<
"' is not a writeable directory" << std::endl;
914 else if( atest != NULL)
967 Pathname targetFilename )
const
970 INT <<
"Media not_attached on provideFileCopy(" << srcFilename
971 <<
"," << targetFilename <<
")" << endl;
976 DBG <<
"provideFileCopy(" << srcFilename <<
"," << targetFilename <<
")" << endl;
982 INT <<
"Error: Not attached on provideFile(" << filename <<
")" << endl;
987 DBG <<
"provideFile(" << filename <<
")" << endl;
1002 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
1006 getDir( dirname,
false );
1007 MIL <<
"provideDir(" << dirname <<
")" << endl;
1021 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1026 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1044 if ( info.isFile() ) {
1046 }
else if ( info.isDir() ) {
1064 const Pathname & dirname,
bool dots )
const
1069 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1074 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1086 const Pathname & dirname,
bool dots )
const
1091 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1096 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1111 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1115 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1125 const Pathname & dirname,
bool dots )
const
1133 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1134 retlist.push_back( it->name );
1145 const Pathname & dirname,
bool dots )
const
1150 Pathname dirFile = dirname +
"directory.yast";
1152 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1157 ERR <<
"Unable to load '" <<
localPath( dirFile ) <<
"'" << endl;
1163 while(
getline( dir, line ) ) {
1164 if ( line.empty() )
continue;
1165 if ( line ==
"directory.yast" )
continue;
1170 if ( *line.rbegin() ==
'/' ) {
1171 line.erase( line.end()-1 );
1176 if ( line ==
"." || line ==
".." )
continue;
1178 if ( *line.begin() ==
'.' )
continue;
1194 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1210 if( info.isFile() ) {
1225 if (
copy(
localPath( srcFilename ), targetFilename ) != 0 ) {
1244 if( info.isDir() ) {
1264 const Pathname & dirname,
bool dots )
const
1267 if( ! info.isDir() ) {
1271 #if NONREMOTE_DIRECTORY_YAST
1281 int res =
readdir( retlist, info.path(), dots );
1285 #if NONREMOTE_DIRECTORY_YAST
1291 #if NONREMOTE_DIRECTORY_YAST
1308 const Pathname & dirname,
bool dots )
const
1311 if( ! info.isDir() ) {
1315 #if NONREMOTE_DIRECTORY_YAST
1325 int res =
readdir( retlist, info.path(), dots );
1329 #if NONREMOTE_DIRECTORY_YAST
1334 #if NONREMOTE_DIRECTORY_YAST
1351 if( info.isDir() ) {
1354 return info.isExist();
1363 unsigned int & index)
const
1366 if (!devices.empty())
1370 DBG <<
"No devices for this medium" << endl;