cataloger.cc

Go to the documentation of this file.
00001 #include "config.h"
00002 
00003 #include <iostream>
00004 #include <string>
00005 #include <vector>
00006 
00007 #include "asserts.h"
00008 #include "error.h"
00009 #include "estring.h"
00010 #include "fs.h"
00011 #include "rconfig.h"
00012 #include "timer.h"
00013 #include "logger.h"
00014 #include "vaulter.h"
00015 
00016 #include "cataloger.h"
00017 
00018 //-----------------------------------------------------------------------------
00019 
00020 /** C'tor */
00021 catalog_manager::catalog_manager()
00022 {
00023         if (this != &cataloger)
00024                 throw(INTERNAL_ERROR(0,"Attempt to allocate multiple catalog managers"));
00025 
00026         clear();
00027 }
00028 
00029 /** Reset the catalog manager */
00030 void catalog_manager::clear(void)
00031 {
00032         m_initialized = false;
00033 }
00034 
00035 /** Initialize the catalog manager */
00036 void catalog_manager::init(void)
00037 {
00038         m_initialized = true;
00039 }
00040 
00041 /** Return the initialized status */
00042 const bool catalog_manager::initialized(void) const
00043 {
00044         return(m_initialized);
00045 }
00046 
00047 /** Erase the contents of the catalog */
00048 void catalog_manager::erase(void)
00049 {
00050         subdirectory subdir;
00051         subdirectory::const_iterator sdi;
00052         std::string path;
00053         estring lstr;
00054 
00055         if (!initialized())
00056                 throw(INTERNAL_ERROR(0,"Catalog manager not initialized"));
00057 
00058         if (config.link_catalog_dir().size() == 0)
00059                 return;
00060         subdir.path(config.link_catalog_dir());
00061         if (subdir.size() == 0)
00062                 return;
00063         lstr = "Cataloger - Erasing old link catalog...\n";
00064         logger.write(lstr);
00065         for (sdi = subdir.begin(); sdi != subdir.end(); ++sdi) {
00066                 TRY_nomem(path = config.link_catalog_dir());
00067                 TRY_nomem(path += "/");
00068                 TRY_nomem(path += *sdi);
00069                 TRY_nomem(path = reform_path(path));
00070                 rm_recursive(path);
00071         }
00072         lstr = "Cataloger - Finished erasing link catalog\n";
00073         logger.write(lstr);
00074 }
00075 
00076 /** Create or update the catalog */
00077 void catalog_manager::catalog(void)
00078 {
00079         estring cpath, vpath;
00080         subdirectory subdir;
00081         subdirectory::const_iterator si;
00082         configuration_manager::vaults_type::const_iterator vi;
00083         estring lstr;
00084 
00085         if (!initialized())
00086                 throw(INTERNAL_ERROR(0,"Catalog manager not initialized"));
00087 
00088         if (config.link_catalog_dir().size() == 0)
00089                 return;
00090 
00091         erase();
00092         lstr = "Cataloger - Building link catalog...\n";
00093         logger.write(lstr);
00094         for (
00095                 vi = config.vaults().begin();
00096                 vi != config.vaults().end();
00097                 ++vi)
00098         {
00099                 subdir.path(*vi);
00100                 if (subdir.size() == 0)
00101                         continue;
00102                 for (si = subdir.begin(); si != subdir.end(); ++si) {
00103                         if (!is_timestamp(*si))
00104                                 continue;
00105 
00106                         vpath = *vi;
00107                         vpath += "/";
00108                         vpath += *si;
00109                         vpath = reform_path(vpath);
00110 
00111                         cpath = config.link_catalog_dir();
00112                         cpath += "/";
00113                         cpath += *si;
00114                         cpath = reform_path(cpath);
00115 
00116                         lstr = "Linking: ";
00117                         lstr += vpath;
00118                         lstr += "\n";
00119                         logger.write(lstr);
00120                         lstr = "     To: ";
00121                         lstr += cpath;
00122                         lstr += "\n";
00123                         logger.write(lstr);
00124 
00125                         TRY_log(mk_relative_symlink(vpath, cpath),"Could not link");
00126                 }
00127         }
00128         lstr = "Cataloger - Finished building link catalog\n";
00129         logger.write(lstr);
00130 }
00131 
00132 //-----------------------------------------------------------------------------
00133 
00134 /** The global catalog manager */
00135 catalog_manager cataloger;
00136 

Generated on Tue Jul 1 12:09:27 2008 for rvm by  doxygen 1.5.1