33 #define NONREMOTE_DIRECTORY_YAST 1 38 Pathname MediaHandler::_attachPrefix(
"");
54 MediaHandler::MediaHandler (
const Url & url_r,
55 const Pathname & attach_point_r,
56 const Pathname & urlpath_below_attachpoint_r,
57 const bool does_download_r )
61 , _relativeRoot( urlpath_below_attachpoint_r)
62 , _does_download( does_download_r )
67 Pathname real_attach_point(
getRealPath(attach_point_r.asString()));
69 if ( !real_attach_point.empty() ) {
74 PathInfo adir( real_attach_point );
85 && !real_attach_point.absolute()) )
87 ERR <<
"Provided attach point is not a absolute directory: " 128 char *ptr = ::realpath(path.c_str(), NULL);
138 char buff[PATH_MAX + 2];
139 memset(buff,
'\0',
sizeof(buff));
140 if( ::realpath(path.c_str(), buff) != NULL)
146 char buff[PATH_MAX + 2];
147 memset(buff,
'\0',
sizeof(buff));
148 if( ::realpath(path.c_str(), buff) != NULL)
160 return zypp::Pathname(
getRealPath(path.asString()));
176 INT <<
"MediaHandler deleted with media attached." << endl;
180 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
192 MIL <<
"Deleted default attach point " << path << endl;
194 ERR <<
"Failed to Delete default attach point " << path
195 <<
" errno(" << res <<
")" << endl;
201 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
315 if( attach_prefix.empty())
317 MIL <<
"Reseting to built-in attach point prefixes." 319 MediaHandler::_attachPrefix = attach_prefix;
325 MIL <<
"Setting user defined attach point prefix: " 326 << attach_prefix << std::endl;
327 MediaHandler::_attachPrefix = attach_prefix;
348 if ( ! aroot.empty() )
352 if ( apoint.empty() )
355 if ( ! aroot.empty() )
359 if ( apoint.empty() )
362 if ( ! aroot.empty() )
366 if ( apoint.empty() )
368 ERR <<
"Create attach point: Can't find a writable directory to create an attach point" << std::endl;
372 MIL <<
"Created default attach point " << apoint << std::endl;
382 if( attach_root.empty() || !attach_root.absolute()) {
383 ERR <<
"Create attach point: invalid attach root: '" 384 << attach_root <<
"'" << std::endl;
388 PathInfo adir( attach_root );
389 if( !adir.isDir() || (geteuid() != 0 && !adir.userMayRWX())) {
390 DBG <<
"Create attach point: attach root is not a writable directory: '" 391 << attach_root <<
"'" << std::endl;
395 static bool cleanup_once(
true );
398 cleanup_once =
false;
399 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
400 std::list<std::string> entries;
402 for (
const std::string & entry : entries )
406 PathInfo sdir( attach_root + entry );
408 && sdir.dev() == adir.dev()
411 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
421 if ( ! apoint.empty() )
423 tmpdir.autoCleanup(
false );
427 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
432 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
465 if( ref && !ref->type.empty() && !ref->name.empty())
511 bool _isAttached =
false;
526 DBG <<
"Mount table changed - rereading it" << std::endl;
528 DBG <<
"Forced check of the mount table" << std::endl;
531 for_( e, entries.begin(), entries.end() )
536 bool is_device =
false;
539 dev_info(e->src) && dev_info.isBlk() )
547 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
548 MediaSource media(mtype, e->src, dev_info.devMajor(), dev_info.devMinor());
552 DBG <<
"Found media device " 554 <<
" in the mount table as " << e->src << std::endl;
568 if ( matchMountFs && e->type != ref.
mediaSource->type )
571 matchMountFs =
false;
572 else if ( ( e->type ==
"cifs" || e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
573 matchMountFs =
false;
592 DBG <<
"Found media name " 594 <<
" in the mount table as " << e->src << std::endl;
603 DBG <<
"Found bound media " 605 <<
" in the mount table as " << e->src << std::endl;
616 MIL <<
"Looking for " << ref << endl;
617 if( entries.empty() )
619 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
623 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
627 ERR <<
"Attached media not in mount table any more - forcing reset!" 634 WAR <<
"Attached media not in mount table ..." << std::endl;
675 MIL <<
"Attached: " << *
this << endl;
688 if ( _localRoot.empty() )
695 return _localRoot + pathname.absolutename();
714 MIL <<
"Disconnected: " << *
this << endl;
728 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'" 730 if ( !ejectDev.empty() )
735 DBG <<
"Request to release attached media " 760 else if( !ejectDev.empty() ) {
773 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
792 DBG <<
"Releasing shared media reference only" << std::endl;
796 MIL <<
"Released: " << *
this << endl;
811 MountEntries::const_iterator e;
812 for( e = entries.begin(); e != entries.end(); ++e)
814 bool is_device =
false;
818 dev_info(e->src) && dev_info.isBlk())
823 if( is_device && ref->maj_nr)
825 std::string mtype(matchMountFs ? e->type : ref->type);
826 MediaSource media(mtype, e->src, dev_info.devMajor(), dev_info.devMinor());
828 if( ref->equals( media) && e->type !=
"subfs")
830 DBG <<
"Forcing release of media device " 832 <<
" in the mount table as " 833 << e->src << std::endl;
845 if(!is_device && !ref->maj_nr)
847 std::string mtype(matchMountFs ? e->type : ref->type);
849 if( ref->equals( media))
851 DBG <<
"Forcing release of media name " 853 <<
" in the mount table as " 854 << e->src << std::endl;
880 if( apoint.empty() || !apoint.absolute())
882 ERR <<
"Attach point '" << apoint <<
"' is not absolute" 888 ERR <<
"Attach point '" << apoint <<
"' is not allowed" 893 PathInfo ainfo(apoint);
896 ERR <<
"Attach point '" << apoint <<
"' is not a directory" 905 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory" 913 Pathname apath(apoint +
"XXXXXX");
914 char *atemp = ::strdup( apath.asString().c_str());
916 if( !ainfo.userMayRWX() || atemp == NULL ||
917 (atest=::mkdtemp(atemp)) == NULL)
922 ERR <<
"Attach point '" << ainfo.path()
923 <<
"' is not a writeable directory" << std::endl;
926 else if( atest != NULL)
979 Pathname targetFilename )
const 982 INT <<
"Media not_attached on provideFileCopy(" << srcFilename
983 <<
"," << targetFilename <<
")" << endl;
988 DBG <<
"provideFileCopy(" << srcFilename <<
"," << targetFilename <<
")" << endl;
994 INT <<
"Error: Not attached on provideFile(" << filename <<
")" << endl;
999 DBG <<
"provideFile(" << filename <<
")" << endl;
1014 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
1018 getDir( dirname,
false );
1019 MIL <<
"provideDir(" << dirname <<
")" << endl;
1033 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1038 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1056 if ( info.isFile() ) {
1058 }
else if ( info.isDir() ) {
1076 const Pathname & dirname,
bool dots )
const 1081 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1086 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1098 const Pathname & dirname,
bool dots )
const 1103 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1108 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1123 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1127 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1137 const Pathname & dirname,
bool dots )
const 1145 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1146 retlist.push_back( it->name );
1157 const Pathname & dirname,
bool dots )
const 1162 Pathname dirFile = dirname +
"directory.yast";
1164 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1169 ERR <<
"Unable to load '" <<
localPath( dirFile ) <<
"'" << endl;
1175 while(
getline( dir, line ) ) {
1176 if ( line.empty() )
continue;
1177 if ( line ==
"directory.yast" )
continue;
1182 if ( *line.rbegin() ==
'/' ) {
1183 line.erase( line.end()-1 );
1188 if ( line ==
"." || line ==
".." )
continue;
1190 if ( *line.begin() ==
'.' )
continue;
1206 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1222 if( info.isFile() ) {
1237 if (
copy(
localPath( srcFilename ), targetFilename ) != 0 ) {
1256 if( info.isDir() ) {
1276 const Pathname & dirname,
bool dots )
const 1279 if( ! info.isDir() ) {
1283 #if NONREMOTE_DIRECTORY_YAST 1293 int res =
readdir( retlist, info.path(), dots );
1297 #if NONREMOTE_DIRECTORY_YAST 1303 #if NONREMOTE_DIRECTORY_YAST 1320 const Pathname & dirname,
bool dots )
const 1323 if( ! info.isDir() ) {
1327 #if NONREMOTE_DIRECTORY_YAST 1337 int res =
readdir( retlist, info.path(), dots );
1341 #if NONREMOTE_DIRECTORY_YAST 1346 #if NONREMOTE_DIRECTORY_YAST 1363 if( info.isDir() ) {
1366 return info.isExist();
1375 unsigned int & index)
const 1378 if (!devices.empty())
1382 DBG <<
"No devices for this medium" << endl;
Listentry returned by readdir.
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
static ZConfig & instance()
Singleton ctor.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
String related utilities and Regular expression matching.
static const Pathname & defaultLocation()
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
static const ValueType month
int is_empty_dir(const Pathname &path_r)
Check if the specified directory is empty.
void remember(const Exception &old_r)
Store an other Exception as history.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
std::string getline(std::istream &str)
Read one line from stream.
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).
Provide a new empty temporary directory and recursively delete it when no longer needed.
int unlink(const Pathname &path)
Like 'unlink'.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
std::list< DirEntry > DirContent
Returned by readdir.
Pathname download_mediaMountdir() const
Path where media are preferably mounted or downloaded.
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int rmdir(const Pathname &path)
Like 'rmdir'.
void swap(RW_pointer &rhs)
Base class for Exception.
FileType
File type information.
static Date now()
Return the current time.
std::string getScheme() const
Returns the scheme name of the URL.
Easy-to use interface to the ZYPP dependency resolver.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.