18#include <zypp/TmpPath.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;
159 int res = recursive_rmdir( path );
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;
1034 unlink( info.
path() );
1035 }
else if ( info.
isDir() ) {
1037 recursive_rmdir( info.
path() );
1039 clean_dir( info.
path() );
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
1258 int res = readdir( retlist, info.
path(), dots );
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
1302 int res = readdir( retlist, info.
path(), dots );
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;
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.
std::string getScheme() const
Returns the scheme name of the URL.
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 is_empty_dir(const Pathname &path_r)
Check if the specified directory is empty.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
std::list< DirEntry > DirContent
Returned by readdir.
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)
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.