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 <<
"Resetting 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)
997 INT <<
"Media not_attached on provideFileCopy(" << srcFilename
998 <<
"," << targetFilename <<
")" << endl;
1002 getFileCopy( srcFilename, targetFilename, expectedFileSize_r );
1003 DBG <<
"provideFileCopy(" << srcFilename <<
"," << targetFilename <<
")" << endl;
1009 INT <<
"Error: Not attached on provideFile(" << filename <<
")" << endl;
1013 getFile( filename, expectedFileSize_r );
1014 DBG <<
"provideFile(" << filename <<
")" << endl;
1029 INT <<
"Error: Not attached on provideDir(" << dirname <<
")" << endl;
1033 getDir( dirname,
false );
1034 MIL <<
"provideDir(" << dirname <<
")" << endl;
1048 INT <<
"Error Not attached on provideDirTree(" << dirname <<
")" << endl;
1053 MIL <<
"provideDirTree(" << dirname <<
")" << endl;
1073 }
else if ( info.
isDir() ) {
1091 const Pathname & dirname,
bool dots )
const
1096 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1101 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1113 const Pathname & dirname,
bool dots )
const
1118 INT <<
"Error: Not attached on dirInfo(" << dirname <<
")" << endl;
1123 MIL <<
"dirInfo(" << dirname <<
")" << endl;
1138 INT <<
"Error Not attached on doesFileExist(" << filename <<
")" << endl;
1142 MIL <<
"doesFileExist(" << filename <<
")" << endl;
1152 const Pathname & dirname,
bool dots )
const
1160 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
1161 retlist.push_back( it->name );
1172 const Pathname & dirname,
bool dots )
const
1177 Pathname dirFile = dirname +
"directory.yast";
1179 DBG <<
"provideFile(" << dirFile <<
"): " <<
"OK" << endl;
1184 ERR <<
"Unable to load '" <<
localPath( dirFile ) <<
"'" << endl;
1190 while(
getline( dir, line ) ) {
1191 if ( line.empty() )
continue;
1192 if ( line ==
"directory.yast" )
continue;
1197 if ( *line.rbegin() ==
'/' ) {
1198 line.erase( line.end()-1 );
1203 if ( line ==
"." || line ==
".." )
continue;
1205 if ( *line.begin() ==
'.' )
continue;
1221 <<
" attached; localRoot \"" << obj.
localRoot() <<
"\"";
1250 getFile(srcFilename, expectedFileSize_r);
1252 if (
copy(
localPath( srcFilename ), targetFilename ) != 0 ) {
1271 if( info.
isDir() ) {
1291 const Pathname & dirname,
bool dots )
const
1294 if( ! info.
isDir() ) {
1298#if NONREMOTE_DIRECTORY_YAST
1312#if NONREMOTE_DIRECTORY_YAST
1318#if NONREMOTE_DIRECTORY_YAST
1335 const Pathname & dirname,
bool dots )
const
1338 if( ! info.
isDir() ) {
1342#if NONREMOTE_DIRECTORY_YAST
1356#if NONREMOTE_DIRECTORY_YAST
1361#if NONREMOTE_DIRECTORY_YAST
1378 if( info.
isDir() ) {
1390 unsigned int & index)
const
1393 if (!devices.empty())
1397 DBG <<
"No devices for this medium" << endl;
#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.
Store and operate with byte count.
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::string asString(const DefaultIntegral< Tp, TInitial > &obj)
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.