34 #define NONREMOTE_DIRECTORY_YAST 1 39 Pathname MediaHandler::_attachPrefix(
"");
55 MediaHandler::MediaHandler (
const Url & url_r,
57 const Pathname & urlpath_below_attachpoint_r,
58 const bool does_download_r )
62 , _relativeRoot( urlpath_below_attachpoint_r)
63 , _does_download( does_download_r )
70 if ( !real_attach_point.
empty() ) {
88 ERR <<
"Provided attach point is not a absolute directory: " 129 char *ptr = ::realpath(path.c_str(), NULL);
139 char buff[PATH_MAX + 2];
140 memset(buff,
'\0',
sizeof(buff));
141 if( ::realpath(path.c_str(), buff) != NULL)
147 char buff[PATH_MAX + 2];
148 memset(buff,
'\0',
sizeof(buff));
149 if( ::realpath(path.c_str(), buff) != NULL)
177 INT <<
"MediaHandler deleted with media attached." << endl;
181 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
193 MIL <<
"Deleted default attach point " << path << endl;
195 ERR <<
"Failed to Delete default attach point " << path
196 <<
" errno(" << res <<
")" << endl;
202 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
316 if( attach_prefix.
empty())
318 MIL <<
"Reseting to built-in attach point prefixes." 320 MediaHandler::_attachPrefix = attach_prefix;
326 MIL <<
"Setting user defined attach point prefix: " 327 << attach_prefix << std::endl;
328 MediaHandler::_attachPrefix = attach_prefix;
349 if ( ! aroot.
empty() )
353 if ( apoint.
empty() )
356 if ( ! aroot.
empty() )
360 if ( apoint.
empty() )
363 if ( ! aroot.
empty() )
367 if ( apoint.
empty() )
370 except.addHistory(
_(
"Create attach point: Can't find a writable directory to create an attach point") );
374 MIL <<
"Created default attach point " << apoint << std::endl;
384 ERR <<
"Create attach point: invalid attach root: '" 385 << attach_root <<
"'" << std::endl;
391 DBG <<
"Create attach point: attach root is not a writable directory: '" 392 << attach_root <<
"'" << std::endl;
396 static bool cleanup_once(
true );
399 cleanup_once =
false;
400 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
401 std::list<std::string> entries;
403 for (
const std::string & entry : entries )
407 PathInfo sdir( attach_root + entry );
409 && sdir.
dev() == adir.
dev()
412 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
422 if ( ! apoint.
empty() )
424 tmpdir.autoCleanup(
false );
428 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
433 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
466 if( ref && !ref->type.empty() && !ref->name.empty())
512 bool _isAttached =
false;
527 DBG <<
"Mount table changed - rereading it" << std::endl;
529 DBG <<
"Forced check of the mount table" << std::endl;
532 for_( e, entries.begin(), entries.end() )
537 bool is_device =
false;
540 dev_info(e->src) && dev_info.
isBlk() )
548 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
553 DBG <<
"Found media device " 555 <<
" in the mount table as " << e->src << std::endl;
569 if ( matchMountFs && e->type != ref.
mediaSource->type )
572 matchMountFs =
false;
573 else if ( ( e->type ==
"cifs" || e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
574 matchMountFs =
false;
593 DBG <<
"Found media name " 595 <<
" in the mount table as " << e->src << std::endl;
604 DBG <<
"Found bound media " 606 <<
" in the mount table as " << e->src << std::endl;
617 MIL <<
"Looking for " << ref << endl;
618 if( entries.empty() )
620 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
624 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
628 ERR <<
"Attached media not in mount table any more - forcing reset!" 635 WAR <<
"Attached media not in mount table ..." << std::endl;
676 MIL <<
"Attached: " << *
this << endl;
689 if ( _localRoot.
empty() )
715 MIL <<
"Disconnected: " << *
this << endl;
729 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'" 731 if ( !ejectDev.empty() )
736 DBG <<
"Request to release attached media " 761 else if( !ejectDev.empty() ) {
774 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
793 DBG <<
"Releasing shared media reference only" << std::endl;
797 MIL <<
"Released: " << *
this << endl;
812 MountEntries::const_iterator e;
813 for( e = entries.begin(); e != entries.end(); ++e)
815 bool is_device =
false;
819 dev_info(e->src) && dev_info.
isBlk())
824 if( is_device && ref->maj_nr)
826 std::string mtype(matchMountFs ? e->type : ref->type);
829 if( ref->equals( media) && e->type !=
"subfs")
831 DBG <<
"Forcing release of media device " 833 <<
" in the mount table as " 834 << e->src << std::endl;
846 if(!is_device && !ref->maj_nr)
848 std::string mtype(matchMountFs ? e->type : ref->type);
850 if( ref->equals( media))
852 DBG <<
"Forcing release of media name " 854 <<
" in the mount table as " 855 << e->src << std::endl;
883 ERR <<
"Attach point '" << apoint <<
"' is not absolute" 889 ERR <<
"Attach point '" << apoint <<
"' is not allowed" 897 ERR <<
"Attach point '" << apoint <<
"' is not a directory" 906 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory" 915 char *atemp = ::strdup( apath.
asString().c_str());
918 (atest=::mkdtemp(atemp)) == NULL)
923 ERR <<
"Attach point '" << ainfo.
path()
924 <<
"' is not a writeable directory" << std::endl;
927 else if( atest != NULL)
983 INT <<
"Media not_attached on provideFileCopy(" << srcFilename
984 <<
"," << targetFilename <<
")" << endl;
989 DBG <<
"provideFileCopy(" << srcFilename <<
"," << targetFilename <<
")" << endl;
995 INT <<
"Error: Not attached on provideFile(" << filename <<
")" << endl;
1000 DBG <<
"provideFile(" << filename <<
")" << endl;
1015 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
1019 getDir( dirname,
false );
1020 MIL <<
"provideDir(" << dirname <<
")" << endl;
1034 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1039 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1059 }
else if ( info.
isDir() ) {
1077 const Pathname & dirname,
bool dots )
const 1082 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1087 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1099 const Pathname & dirname,
bool dots )
const 1104 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1109 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1124 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1128 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1138 const Pathname & dirname,
bool dots )
const 1146 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1147 retlist.push_back( it->name );
1158 const Pathname & dirname,
bool dots )
const 1163 Pathname dirFile = dirname +
"directory.yast";
1165 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1170 ERR <<
"Unable to load '" <<
localPath( dirFile ) <<
"'" << endl;
1176 while(
getline( dir, line ) ) {
1177 if ( line.empty() )
continue;
1178 if ( line ==
"directory.yast" )
continue;
1183 if ( *line.rbegin() ==
'/' ) {
1184 line.erase( line.end()-1 );
1189 if ( line ==
"." || line ==
".." )
continue;
1191 if ( *line.begin() ==
'.' )
continue;
1207 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1238 if (
copy(
localPath( srcFilename ), targetFilename ) != 0 ) {
1257 if( info.
isDir() ) {
1277 const Pathname & dirname,
bool dots )
const 1280 if( ! info.
isDir() ) {
1284 #if NONREMOTE_DIRECTORY_YAST 1298 #if NONREMOTE_DIRECTORY_YAST 1304 #if NONREMOTE_DIRECTORY_YAST 1321 const Pathname & dirname,
bool dots )
const 1324 if( ! info.
isDir() ) {
1328 #if NONREMOTE_DIRECTORY_YAST 1342 #if NONREMOTE_DIRECTORY_YAST 1347 #if NONREMOTE_DIRECTORY_YAST 1364 if( info.
isDir() ) {
1376 unsigned int & index)
const 1379 if (!devices.empty())
1383 DBG <<
"No devices for this medium" << endl;
std::string getScheme() const
Returns the scheme name of the URL.
Listentry returned by readdir.
const Pathname & path() const
Return current Pathname.
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
static ZConfig & instance()
Singleton ctor.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\ ", const std::string &sep="\ ", const std::string &sfx="\, const std::string &extro="}")
Print range defined by iterators (multiline style).
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.
unsigned int devMinor() const
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.
Pathname download_mediaMountdir() const
Path where media are preferably mounted or downloaded.
bool empty() const
Test for an empty path.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
std::string getline(std::istream &str)
Read one line from stream.
Provide a new empty temporary directory and recursively delete it when no longer needed.
int unlink(const Pathname &path)
Like 'unlink'.
const std::string & asString() const
String representation.
bool isExist() const
Return whether valid stat info exists.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
std::list< DirEntry > DirContent
Returned by readdir.
bool absolute() const
Test for an absolute path.
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)
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Base class for Exception.
FileType
File type information.
static Date now()
Return the current time.
unsigned int devMajor() const
Wrapper class for ::stat/::lstat.
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.