18#include <zypp/TmpPath.h>
20#include <zypp/base/LogTools.h>
21#include <zypp/base/Gettext.h>
22#include <zypp/base/String.h>
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: "
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)
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."
325 MIL <<
"Setting user defined attach point prefix: "
326 << attach_prefix << std::endl;
348 if ( ! aroot.
empty() )
352 if ( apoint.
empty() )
355 if ( ! aroot.
empty() )
359 if ( apoint.
empty() )
362 if ( ! aroot.
empty() )
366 if ( apoint.
empty() )
369 except.addHistory(
_(
"Create attach point: Can't find a writable directory to create an attach point") );
373 MIL <<
"Created default attach point " << apoint << std::endl;
383 ERR <<
"Create attach point: invalid attach root: '"
384 << attach_root <<
"'" << std::endl;
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() )
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);
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;
620 DBG <<
"Found bound media "
622 <<
" in the mount table as " << e->src << std::endl;
631 MIL <<
"Looking for " << ref << endl;
632 if( entries.empty() )
634 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
638 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
642 ERR <<
"Attached media not in mount table any more - forcing reset!"
649 WAR <<
"Attached media not in mount table ..." << std::endl;
690 MIL <<
"Attached: " << *
this << endl;
703 if ( _localRoot.
empty() )
729 MIL <<
"Disconnected: " << *
this << endl;
743 DBG <<
"Request to release media - not attached; eject '" << ejectDev <<
"'"
745 if ( !ejectDev.empty() )
750 DBG <<
"Request to release attached media "
775 else if( !ejectDev.empty() ) {
788 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
807 DBG <<
"Releasing shared media reference only" << std::endl;
811 MIL <<
"Released: " << *
this << endl;
826 MountEntries::const_iterator e;
827 for( e = entries.begin(); e != entries.end(); ++e)
829 bool is_device =
false;
833 dev_info(e->src) && dev_info.
isBlk())
838 if( is_device && ref->maj_nr)
840 std::string mtype(matchMountFs ? e->type : ref->type);
843 if( ref->equals( media) && e->type !=
"subfs")
845 DBG <<
"Forcing release of media device "
847 <<
" in the mount table as "
848 << e->src << std::endl;
860 if(!is_device && !ref->maj_nr)
862 std::string mtype(matchMountFs ? e->type : ref->type);
864 if( ref->equals( media))
866 DBG <<
"Forcing release of media name "
868 <<
" in the mount table as "
869 << e->src << std::endl;
897 ERR <<
"Attach point '" << apoint <<
"' is not absolute"
903 ERR <<
"Attach point '" << apoint <<
"' is not allowed"
911 ERR <<
"Attach point '" << apoint <<
"' is not a directory"
920 ERR <<
"Attach point '" << apoint <<
"' is not a empty directory"
929 char *atemp = ::strdup( apath.
asString().c_str());
932 (atest=::mkdtemp(atemp)) == NULL)
937 ERR <<
"Attach point '" << ainfo.
path()
938 <<
"' is not a writeable directory" << std::endl;
941 else if( atest != NULL)
996 INT <<
"Media not_attached on provideFileCopy(" << srcFile
997 <<
"," << targetFilename <<
")" << endl;
1002 DBG <<
"provideFileCopy(" << srcFile <<
"," << targetFilename <<
")" << endl;
1008 INT <<
"Error: Not attached on provideFile(" << file <<
")" << endl;
1013 DBG <<
"provideFile(" << file <<
")" << endl;
1028 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
1032 getDir( dirname,
false );
1033 MIL <<
"provideDir(" << dirname <<
")" << endl;
1047 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1052 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1072 }
else if ( info.
isDir() ) {
1090 const Pathname & dirname,
bool dots )
const
1095 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1100 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1112 const Pathname & dirname,
bool dots )
const
1117 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1122 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1137 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1141 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1151 const Pathname & dirname,
bool dots )
const
1159 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1160 retlist.push_back( it->name );
1171 const Pathname & dirname,
bool dots )
const
1178 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1183 ERR <<
"Unable to load '" <<
localPath( dirFile.filename() ) <<
"'" << endl;
1189 while(
getline( dir, line ) ) {
1190 if ( line.empty() )
continue;
1191 if ( line ==
"directory.yast" )
continue;
1196 if ( *line.rbegin() ==
'/' ) {
1197 line.erase( line.end()-1 );
1202 if ( line ==
"." || line ==
".." )
continue;
1204 if ( *line.begin() ==
'.' )
continue;
1220 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1258 if( info.
isDir() ) {
1278 const Pathname & dirname,
bool dots )
const
1281 if( ! info.
isDir() ) {
1285#if NONREMOTE_DIRECTORY_YAST
1299#if NONREMOTE_DIRECTORY_YAST
1305#if NONREMOTE_DIRECTORY_YAST
1322 const Pathname & dirname,
bool dots )
const
1325 if( ! info.
isDir() ) {
1329#if NONREMOTE_DIRECTORY_YAST
1343#if NONREMOTE_DIRECTORY_YAST
1348#if NONREMOTE_DIRECTORY_YAST
1365 if( info.
isDir() ) {
1377 unsigned int & index)
const
1380 if (!devices.empty())
1384 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 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 unlink(const Pathname &path)
Like 'unlink'.
int rmdir(const Pathname &path)
Like 'rmdir'.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
std::list< DirEntry > DirContent
Returned by readdir.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
std::string getline(std::istream &str)
Read one line from stream.
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
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.