18#include <zypp/TmpPath.h>
20#include <zypp/base/LogTools.h>
21#include <zypp/base/Gettext.h>
22#include <zypp/base/String.h>
26#include <zypp-media/Mount>
34#define NONREMOTE_DIRECTORY_YAST 1
88 ERR <<
"Provided attach point is not a absolute directory: "
146 INT <<
"MediaHandler deleted with media attached." << endl;
150 DBG <<
"MediaHandler - checking if to remove attach point" << endl;
160 int res = recursive_rmdir( path );
162 MIL <<
"Deleted default attach point " << path << endl;
164 ERR <<
"Failed to Delete default attach point " << path
165 <<
" errno(" <<
res <<
")" << endl;
171 DBG <<
"MediaHandler - attachpoint is not temporary" << endl;
287 MIL <<
"Resetting to built-in attach point prefixes."
295 MIL <<
"Setting user defined attach point prefix: "
318 if ( !
aroot.empty() )
325 if ( !
aroot.empty() )
332 if ( !
aroot.empty() )
339 except.addHistory(
_(
"Create attach point: Can't find a writable directory to create an attach point") );
343 MIL <<
"Created default attach point " <<
apoint << std::endl;
353 ERR <<
"Create attach point: invalid attach root: '"
360 DBG <<
"Create attach point: attach root is not a writable directory: '"
369 DBG <<
"Look for orphaned attach points in " <<
adir << std::endl;
370 std::list<std::string> entries;
372 for (
const std::string &
entry : entries )
381 DBG <<
"Remove orphaned attach point " <<
sdir << std::endl;
393 tmpdir.autoCleanup(
false );
397 ERR <<
"Unable to resolve real path for attach point " <<
tmpdir << std::endl;
402 ERR <<
"Unable to create attach point below " <<
attach_root << std::endl;
435 if( ref && !ref->type.empty() && !ref->name.empty())
496 DBG <<
"Mount table changed - rereading it" << std::endl;
498 DBG <<
"Forced check of the mount table" << std::endl;
501 for_(
e, entries.begin(), entries.end() )
516 DBG <<
"Found media device "
518 <<
" in the mount table as " <<
e->src << std::endl;
536 else if ( (
e->type ==
"cifs" ||
e->type ==
"smb" ) && ( ref.
mediaSource->type ==
"cifs" || ref.
mediaSource->type ==
"smb" ) )
556 DBG <<
"Found media name "
558 <<
" in the mount table as " <<
e->src << std::endl;
567 DBG <<
"Found bound media "
569 <<
" in the mount table as " <<
e->src << std::endl;
584 DBG <<
"Found bound media "
586 <<
" in the mount table as " <<
e->src << std::endl;
595 MIL <<
"Looking for " << ref << endl;
596 if( entries.empty() )
598 ERR <<
"Unable to find any entry in the /etc/mtab file" << std::endl;
602 dumpRange(
DBG <<
"MountEntries: ", entries.begin(), entries.end() ) << endl;
606 ERR <<
"Attached media not in mount table any more - forcing reset!"
613 WAR <<
"Attached media not in mount table ..." << std::endl;
654 MIL <<
"Attached: " << *
this << endl;
693 MIL <<
"Disconnected: " << *
this << endl;
707 DBG <<
"Request to release media - not attached; eject '" <<
ejectDev <<
"'"
714 DBG <<
"Request to release attached media "
749 manager.forceReleaseShared(media);
752 DBG <<
"Releasing media (forced) " <<
_mediaSource->asString() << std::endl;
771 DBG <<
"Releasing shared media reference only" << std::endl;
775 MIL <<
"Released: " << *
this << endl;
790 MountEntries::const_iterator
e;
791 for(
e = entries.begin();
e != entries.end(); ++
e)
807 if( ref->equals( media) &&
e->type !=
"subfs")
809 DBG <<
"Forcing release of media device "
811 <<
" in the mount table as "
812 <<
e->src << std::endl;
828 if( ref->equals( media))
830 DBG <<
"Forcing release of media name "
832 <<
" in the mount table as "
833 <<
e->src << std::endl;
861 ERR <<
"Attach point '" <<
apoint <<
"' is not absolute"
867 ERR <<
"Attach point '" <<
apoint <<
"' is not allowed"
875 ERR <<
"Attach point '" <<
apoint <<
"' is not a directory"
884 ERR <<
"Attach point '" <<
apoint <<
"' is not a empty directory"
893 char *
atemp = ::strdup(
apath.asString().c_str());
901 ERR <<
"Attach point '" <<
ainfo.path()
902 <<
"' is not a writeable directory" << std::endl;
940 if(
am1.mediaSource &&
am2.mediaSource)
942 return am1.mediaSource->equals( *(
am2.mediaSource));
960 INT <<
"Media not_attached on provideFileCopy(" <<
srcFile
972 INT <<
"Error: Not attached on provideFile(" << file <<
")" << endl;
977 DBG <<
"provideFile(" << file <<
")" << endl;
992 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
997 MIL <<
"provideDir(" << dirname <<
")" << endl;
1011 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1016 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1035 unlink( info.
path() );
1036 }
else if ( info.
isDir() ) {
1038 recursive_rmdir( info.
path() );
1040 clean_dir( info.
path() );
1059 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1064 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1081 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1086 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1101 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1105 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1123 for ( filesystem::DirContent::const_iterator
it = content.begin();
it != content.end(); ++
it ) {
1142 DBG <<
"provideFile(" <<
dirFile <<
"): " <<
"OK" << endl;
1153 while( getline( dir,
line ) ) {
1154 if (
line.empty() )
continue;
1155 if (
line ==
"directory.yast" )
continue;
1160 if ( *
line.rbegin() ==
'/' ) {
1166 if (
line ==
"." ||
line ==
".." )
continue;
1168 if ( *
line.begin() ==
'.' )
continue;
1183 str <<
obj.url() << (
obj.isAttached() ?
"" :
" not" )
1184 <<
" attached; localRoot \"" <<
obj.localRoot() <<
"\"";
1222 if( info.
isDir() ) {
1245 if( ! info.
isDir() ) {
1249#if NONREMOTE_DIRECTORY_YAST
1263#if NONREMOTE_DIRECTORY_YAST
1269#if NONREMOTE_DIRECTORY_YAST
1289 if( ! info.
isDir() ) {
1293#if NONREMOTE_DIRECTORY_YAST
1307#if NONREMOTE_DIRECTORY_YAST
1312#if NONREMOTE_DIRECTORY_YAST
1329 if( info.
isDir() ) {
1341 unsigned int & index)
const
1348 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.
std::list< DirEntry > DirContent
Returned by readdir.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
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) noexcept
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.