18 #include <zypp/TmpPath.h> 19 #include <zypp/Date.h> 20 #include <zypp/base/LogTools.h> 21 #include <zypp/base/Gettext.h> 22 #include <zypp/base/String.h> 25 #include <zypp-media/Mount> 33 #define NONREMOTE_DIRECTORY_YAST 1 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 )
69 if ( !real_attach_point.
empty() ) {
87 ERR <<
"Provided attach point is not a absolute directory: " 145 INT <<
"MediaHandler deleted with media attached." << endl;
149 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
161 MIL <<
"Deleted default attach point " << path << endl;
163 ERR <<
"Failed to Delete default attach point " << path
164 <<
" errno(" << res <<
")" << endl;
170 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
284 if( attach_prefix.
empty())
286 MIL <<
"Resetting to built-in attach point prefixes." 294 MIL <<
"Setting user defined attach point prefix: " 295 << attach_prefix << std::endl;
317 if ( ! aroot.
empty() )
321 if ( apoint.
empty() )
324 if ( ! aroot.
empty() )
328 if ( apoint.
empty() )
331 if ( ! aroot.
empty() )
335 if ( apoint.
empty() )
338 except.addHistory(
_(
"Create attach point: Can't find a writable directory to create an attach point") );
342 MIL <<
"Created default attach point " << apoint << std::endl;
352 ERR <<
"Create attach point: invalid attach root: '" 353 << attach_root <<
"'" << std::endl;
359 DBG <<
"Create attach point: attach root is not a writable directory: '" 360 << attach_root <<
"'" << std::endl;
364 static bool cleanup_once(
true );
367 cleanup_once =
false;
368 DBG <<
"Look for orphaned attach points in " << adir << std::endl;
369 std::list<std::string> entries;
371 for (
const std::string & entry : entries )
375 PathInfo sdir( attach_root + entry );
377 && sdir.
dev() == adir.
dev()
380 DBG <<
"Remove orphaned attach point " << sdir << std::endl;
390 if ( ! apoint.
empty() )
396 ERR <<
"Unable to resolve real path for attach point " << tmpdir << std::endl;
401 ERR <<
"Unable to create attach point below " << attach_root << std::endl;
434 if( ref && !ref->type.empty() && !ref->name.empty())
480 bool _isAttached =
false;
495 DBG <<
"Mount table changed - rereading it" << std::endl;
497 DBG <<
"Forced check of the mount table" << std::endl;
500 for_( e, entries.begin(), entries.end() )
505 bool is_device = e->isBlockDevice();
510 std::string mtype(matchMountFs ? e->type : ref.
mediaSource->type);
515 DBG <<
"Found media device " 517 <<
" in the mount table as " << e->src << std::endl;
531 if ( matchMountFs && e->type != ref.
mediaSource->type )
534 matchMountFs =
false;
535 else if ( ( e->type ==
"cifs" || e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
536 matchMountFs =
false;
555 DBG <<
"Found media name " 557 <<
" in the mount table as " << e->src << std::endl;
566 DBG <<
"Found bound media " 568 <<
" in the mount table as " << e->src << std::endl;
583 DBG <<
"Found bound media " 585 <<
" in the mount table as " << e->src << std::endl;
594 MIL <<
"Looking for " << ref << endl;
595 if( entries.empty() )
597 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
601 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
605 ERR <<
"Attached media not in mount table any more - forcing reset!" 612 WAR <<
"Attached media not in mount table ..." << std::endl;
653 MIL <<
"Attached: " << *
this << endl;
666 if ( _localRoot.
empty() )
692 MIL <<
"Disconnected: " << *
this << endl;
706 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'" 708 if ( !ejectDev.empty() )
713 DBG <<
"Request to release attached media " 738 else if( !ejectDev.empty() ) {
751 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
770 DBG <<
"Releasing shared media reference only" << std::endl;
774 MIL <<
"Released: " << *
this << endl;
789 MountEntries::const_iterator e;
790 for( e = entries.begin(); e != entries.end(); ++e)
792 bool is_device =
false;
796 dev_info(e->src) && dev_info.
isBlk())
801 if( is_device && ref->maj_nr)
803 std::string mtype(matchMountFs ? e->type : ref->type);
806 if( ref->equals( media) && e->type !=
"subfs")
808 DBG <<
"Forcing release of media device " 810 <<
" in the mount table as " 811 << e->src << std::endl;
823 if(!is_device && !ref->maj_nr)
825 std::string mtype(matchMountFs ? e->type : ref->type);
827 if( ref->equals( media))
829 DBG <<
"Forcing release of media name " 831 <<
" in the mount table as " 832 << e->src << std::endl;
860 ERR <<
"Attach point '" << apoint <<
"' is not absolute" 866 ERR <<
"Attach point '" << apoint <<
"' is not allowed" 874 ERR <<
"Attach point '" << apoint <<
"' is not a directory" 883 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory" 892 char *atemp = ::strdup( apath.
asString().c_str());
895 (atest=::mkdtemp(atemp)) == NULL)
900 ERR <<
"Attach point '" << ainfo.
path()
901 <<
"' is not a writeable directory" << std::endl;
904 else if( atest != NULL)
959 INT <<
"Media not_attached on provideFileCopy(" << srcFile
960 <<
"," << targetFilename <<
")" << endl;
965 DBG <<
"provideFileCopy(" << srcFile <<
"," << targetFilename <<
")" << endl;
971 INT <<
"Error: Not attached on provideFile(" << file <<
")" << endl;
976 DBG <<
"provideFile(" << file <<
")" << endl;
991 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
996 MIL <<
"provideDir(" << dirname <<
")" << endl;
1010 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1015 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1035 }
else if ( info.
isDir() ) {
1053 const Pathname & dirname,
bool dots )
const 1058 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1063 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1075 const Pathname & dirname,
bool dots )
const 1080 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1085 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1100 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1104 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1114 const Pathname & dirname,
bool dots )
const 1122 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1123 retlist.push_back( it->name );
1134 const Pathname & dirname,
bool dots )
const 1141 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1146 ERR <<
"Unable to load '" <<
localPath( dirFile.filename() ) <<
"'" << endl;
1152 while(
getline( dir, line ) ) {
1153 if ( line.empty() )
continue;
1154 if ( line ==
"directory.yast" )
continue;
1159 if ( *line.rbegin() ==
'/' ) {
1160 line.erase( line.end()-1 );
1165 if ( line ==
"." || line ==
".." )
continue;
1167 if ( *line.begin() ==
'.' )
continue;
1183 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1221 if( info.
isDir() ) {
1241 const Pathname & dirname,
bool dots )
const 1244 if( ! info.
isDir() ) {
1248 #if NONREMOTE_DIRECTORY_YAST 1262 #if NONREMOTE_DIRECTORY_YAST 1268 #if NONREMOTE_DIRECTORY_YAST 1285 const Pathname & dirname,
bool dots )
const 1288 if( ! info.
isDir() ) {
1292 #if NONREMOTE_DIRECTORY_YAST 1306 #if NONREMOTE_DIRECTORY_YAST 1311 #if NONREMOTE_DIRECTORY_YAST 1328 if( info.
isDir() ) {
1340 unsigned int & index)
const 1343 if (!devices.empty())
1347 DBG <<
"No devices for this medium" << endl;
std::string getScheme() const
Returns the scheme name of the URL.
std::string asString(const Patch::Category &obj)
bool autoCleanup() const
Whether path is valid and deleted when the last reference drops.
Listentry returned by readdir.
const Pathname & path() const
Return current Pathname.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Pathname realpath() const
Returns this path as the absolute canonical pathname.
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).
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
String related utilities and Regular expression matching.
static const Pathname & defaultLocation()
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.