PlaindirImpl.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
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, selfSourceRef(), true );
00057 }
00058 
00059 int PlaindirImpl::extract_packages_from_directory (ResStore & store, const Pathname & path, Source_Ref source, bool recursive)
00060 {
00061   using target::rpm::RpmHeader;
00062 
00063   Pathname filename;
00064   PathInfo magic;
00065   bool distro_magic, pkginfo_magic;
00066 
00067   DBG << "extract_packages_from_directory(.., " << path << ", " << source.alias() << ", " << recursive << ")" << endl;
00068 
00069     /*
00070         Check for magic files that indicate how to treat the
00071         directory.  The files aren't read -- it is sufficient that
00072         they exist.
00073     */
00074 
00075     magic = PathInfo( path + "/RC_SKIP" );
00076     if (magic.isExist()) {
00077       return 0;
00078     }
00079 
00080     magic = PathInfo( path + "/RC_RECURSIVE" );
00081     if (magic.isExist())
00082       recursive = true;
00083 
00084     magic = PathInfo( path + "/RC_BY_DISTRO" );
00085     distro_magic = magic.isExist();
00086 
00087     pkginfo_magic = true;
00088     magic = PathInfo( path + "/RC_IGNORE_PKGINFO" );
00089     if (magic.isExist())
00090       pkginfo_magic = false;
00091 
00092 
00093     std::list<std::string> dircontent;
00094     if (filesystem::readdir( dircontent, path, false) != 0) {           // dont look for dot files
00095       ERR << "readdir " << path << " failed" << endl;
00096       return -1;
00097     }
00098 
00099     for (std::list<std::string>::const_iterator it = dircontent.begin(); it != dircontent.end(); ++it) {
00100       Pathname file_path = path + *it;
00101       PathInfo file_info( file_path );
00102       if (recursive && file_info.isDir()) {
00103 
00104         extract_packages_from_directory( store, file_path, source, recursive );
00105 
00106       } else if (file_info.isFile() && file_path.extension() == ".rpm" ) {
00107         RpmHeader::constPtr header = RpmHeader::readPackage( file_path, RpmHeader::NOSIGNATURE );
00108 #warning FIX creation of Package from src.rpm header
00109         Package::Ptr package = target::rpm::RpmDb::makePackageFromHeader( header, NULL, *it, source );
00110         if (package != NULL) {
00111           DBG << "Adding package " << *package << endl;
00112           store.insert( package );
00113         }
00114       }
00115     }
00116     return 0;
00117 }
00118 
00119 
00120 
00121 
00122 
00124     } // namespace plaindir
00127   } // namespace source
00130 } // namespace zypp

Generated on Tue Nov 28 16:49:32 2006 for zypp by  doxygen 1.5.0