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
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;
286 MIL <<
"Resetting to built-in attach point prefixes."
294 MIL <<
"Setting user defined attach point prefix: "
317 if ( !
aroot.empty() )
324 if ( !
aroot.empty() )
331 if ( !
aroot.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: '"
359 DBG <<
"Create attach point: attach root is not a writable directory: '"
368 DBG <<
"Look for orphaned attach points in " <<
adir << std::endl;
369 std::list<std::string> entries;
371 for (
const std::string &
entry : entries )
380 DBG <<
"Remove orphaned attach point " <<
sdir << std::endl;
392 tmpdir.autoCleanup(
false );
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())
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() )
515 DBG <<
"Found media device "
517 <<
" in the mount table as " <<
e->src << std::endl;
535 else if ( (
e->type ==
"cifs" ||
e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
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;
692 MIL <<
"Disconnected: " << *
this << endl;
706 DBG <<
"Request to release media - not attached; eject '" <<
ejectDev <<
"'"
713 DBG <<
"Request to release attached media "
748 manager.forceReleaseShared(media);
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)
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;
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());
900 ERR <<
"Attach point '" <<
ainfo.path()
901 <<
"' is not a writeable directory" << std::endl;
939 if(
am1.mediaSource &&
am2.mediaSource)
941 return am1.mediaSource->equals( *(
am2.mediaSource));
959 INT <<
"Media not_attached on provideFileCopy(" <<
srcFile
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() );
1058 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1063 MIL <<
"dirInfo(" << dirname <<
")" << endl;
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;
1122 for ( filesystem::DirContent::const_iterator
it = content.begin();
it != content.end(); ++
it ) {
1141 DBG <<
"provideFile(" <<
dirFile <<
"): " <<
"OK" << endl;
1152 while( getline( dir,
line ) ) {
1153 if (
line.empty() )
continue;
1154 if (
line ==
"directory.yast" )
continue;
1159 if ( *
line.rbegin() ==
'/' ) {
1165 if (
line ==
"." ||
line ==
".." )
continue;
1167 if ( *
line.begin() ==
'.' )
continue;
1182 str <<
obj.url() << (
obj.isAttached() ?
"" :
" not" )
1183 <<
" attached; localRoot \"" <<
obj.localRoot() <<
"\"";
1221 if( info.
isDir() ) {
1244 if( ! info.
isDir() ) {
1248#if NONREMOTE_DIRECTORY_YAST
1262#if NONREMOTE_DIRECTORY_YAST
1268#if NONREMOTE_DIRECTORY_YAST
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
1347 DBG <<
"No devices for this medium" << endl;
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
static const ValueType month
static Date now()
Return the current time.
Base class for Exception.
std::string getScheme() const
Returns the scheme name of the URL.
static ZConfig & instance()
Singleton ctor.
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
bool isExist() const
Return whether valid stat info exists.
const std::string & asString() const
String representation.
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()
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.