00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 00014 #include "zypp/base/Logger.h" 00015 #include "zypp/base/WatchFile.h" 00016 #include "zypp/base/Sysconfig.h" 00017 #include "zypp/base/SerialNumber.h" 00018 00019 #include "zypp/capability/FilesystemCap.h" 00020 00021 using namespace std; 00022 00024 namespace zypp 00025 { 00026 00027 namespace capability 00028 { 00029 00030 namespace 00031 { 00032 const Pathname & sysconfigStoragePath() 00033 { 00034 static Pathname _p( "/etc/sysconfig/storage" ); 00035 return _p; 00036 } 00037 } 00038 00039 IMPL_PTR_TYPE(FilesystemCap) 00040 00041 00042 FilesystemCap::FilesystemCap( const Resolvable::Kind & refers_r, 00043 const std::string & name_r ) 00044 : CapabilityImpl( refers_r ) 00045 , _name( name_r ) 00046 {} 00047 00048 const CapabilityImpl::Kind & FilesystemCap::kind() const 00049 { return CapTraits<Self>::kind; } 00050 00051 CapMatch FilesystemCap::matches( const CapabilityImpl::constPtr & rhs ) const 00052 { 00053 if ( sameKindAndRefers( rhs ) ) 00054 { 00055 intrusive_ptr<const Self> filesystemrhs( asKind<Self>(rhs) ); 00056 if ( isEvalCmd() == filesystemrhs->isEvalCmd() ) 00057 return CapMatch::irrelevant; 00058 00059 return( isEvalCmd() ? filesystemrhs->evaluate() : evaluate() ); 00060 } 00061 return false; 00062 } 00063 00064 std::string FilesystemCap::encode() const 00065 { 00066 std::string ret( "filesystem(" ); 00067 ret += _name; 00068 ret += ")"; 00069 return ret; 00070 } 00071 00072 std::string FilesystemCap::index() const 00073 { 00074 return "filesystem()"; 00075 } 00076 00077 bool FilesystemCap::isEvalCmd() const 00078 { return _name.empty(); } 00079 00080 00081 00082 bool FilesystemCap::evaluate() const 00083 { 00084 static SerialNumberWatcher sysconfigStorage; 00085 static std::set<std::string> fs; 00086 00087 if ( sysconfigStorage.remember( sysconfigStorageSerial() ) ) 00088 { 00089 std::set<std::string> newfs; 00090 str::split( base::sysconfig::read( sysconfigStoragePath() )["USED_FS_LIST"], 00091 std::inserter( newfs, newfs.end() ) ); 00092 fs.swap( newfs ); 00093 } 00094 00095 return( fs.find( _name ) != fs.end() ); 00096 } 00097 00098 const SerialNumber & FilesystemCap::sysconfigStorageSerial() 00099 { 00100 static WatchFile _sysconfigFile( sysconfigStoragePath(), WatchFile::NO_INIT ); 00101 static SerialNumber _serial; 00102 00103 if ( _sysconfigFile.hasChanged() ) 00104 { 00105 _serial.setDirty(); 00106 } 00107 return _serial; 00108 } 00109 00111 } // namespace capability 00114 } // namespace zypp
1.5.3