00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include "zypp/base/Logger.h"
00012
00013 #include "zypp/source/plaindir/PlaindirImpl.h"
00014
00015 using std::endl;
00016 using namespace std;
00017
00019 namespace zypp
00020 {
00021
00022 namespace source
00023 {
00024
00025 namespace plaindir
00026 {
00027
00028 PlaindirImpl::PlaindirImpl()
00029 {
00030
00031 }
00032
00033 PlaindirImpl::~PlaindirImpl()
00034 {
00035
00036 }
00037
00038
00039 void PlaindirImpl::factoryInit()
00040 {
00041 if ( ! ( (url().getScheme() == "file") || (url().getScheme() == "dir") ) )
00042 {
00043 ZYPP_THROW( Exception( "Plaindir only supports local paths, scheme [" + url().getScheme() + "] is not local" ) );
00044 }
00045
00046 MIL << "Plaindir source initialized." << std::endl;
00047 MIL << " Url : " << url() << std::endl;
00048 MIL << " Path : " << path() << std::endl;
00049 }
00050
00051 void PlaindirImpl::createResolvables(Source_Ref source_r)
00052 {
00053 Pathname thePath = Pathname(url().getPathName()) + path();
00054 MIL << "Going to read dir " << thePath << std::endl;
00055
00056 extract_packages_from_directory( _store, thePath, Pathname(), selfSourceRef(), true );
00057 }
00058
00059 int PlaindirImpl::extract_packages_from_directory (ResStore & store, const Pathname & rootpath, const Pathname & subdir, Source_Ref source, bool recursive)
00060 {
00061 using target::rpm::RpmHeader;
00062
00063 Pathname path = rootpath / subdir;
00064
00065 Pathname filename;
00066 PathInfo magic;
00067 bool distro_magic, pkginfo_magic;
00068
00069 DBG << "extract_packages_from_directory(.., " << rootpath << ", " << subdir << ", " << source.alias() << ", " << recursive << ")" << endl;
00070
00071
00072
00073
00074
00075
00076
00077 magic = PathInfo( path + "/RC_SKIP" );
00078 if (magic.isExist()) {
00079 return 0;
00080 }
00081
00082 magic = PathInfo( path + "/RC_RECURSIVE" );
00083 if (magic.isExist())
00084 recursive = true;
00085
00086 magic = PathInfo( path + "/RC_BY_DISTRO" );
00087 distro_magic = magic.isExist();
00088
00089 pkginfo_magic = true;
00090 magic = PathInfo( path + "/RC_IGNORE_PKGINFO" );
00091 if (magic.isExist())
00092 pkginfo_magic = false;
00093
00094
00095 std::list<std::string> dircontent;
00096 if (filesystem::readdir( dircontent, path, false) != 0) {
00097 ERR << "readdir " << path << " failed" << endl;
00098 return -1;
00099 }
00100
00101 for (std::list<std::string>::const_iterator it = dircontent.begin(); it != dircontent.end(); ++it) {
00102 Pathname file_path = path + *it;
00103 PathInfo file_info( file_path );
00104 if (recursive && file_info.isDir()) {
00105
00106 extract_packages_from_directory( store, rootpath, subdir / *it, source, recursive );
00107
00108 } else if (file_info.isFile() && file_path.extension() == ".rpm" ) {
00109 RpmHeader::constPtr header = RpmHeader::readPackage( file_path, RpmHeader::NOSIGNATURE );
00110
00111 if ( ! ( header->isPatchRpm() || header->isDeltaRpm() ) )
00112 {
00113
00114 Package::Ptr package = target::rpm::RpmDb::makePackageFromHeader( header, NULL, subdir / *it, source );
00115 if (package != NULL) {
00116 DBG << "Adding package " << *package << endl;
00117 store.insert( package );
00118 }
00119 }
00120 }
00121 }
00122 return 0;
00123 }
00124
00125
00126
00127
00128
00130 }
00133 }
00136 }