Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DeleteLogsCode.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Thu Nov  8 12:48:54 EST 2001 by ken@xorian.net
00020 //      modified on Fri Sep 13 14:45:45 PDT 1996 by heydon
00021 
00022 /* This is old code that was written to delete the old "weededMPKs" log and
00023    checkpoint files before Tim implemented "VestaLog::prune". It was called
00024    from "CacheS::ResetWeededMPKs" by the lines:
00025 
00026         thread th;
00027         th.fork_and_detach(CacheS_DeleteOldLogs,
00028           (void *)(&Config_WeededLogPath));
00029 
00030    These lines appeared just after the line:
00031 
00032         this->weededMPKsLog->checkpointEnd();
00033 */
00034 
00035 static void CacheS_DeleteOldLogs2(const Text &dirName, int version)
00036   throw (FS::Failure)
00037 {
00038     DIR *dp = opendir(dirName.cchars());
00039     if (dp == (DIR *)NULL)
00040         throw (FS::Failure("opendir", dirName));
00041     struct dirent *ent;
00042     try {
00043         Text fullDirName(dirName); fullDirName += "/";
00044         for (ent = readdir(dp); ent != NULL; ent = readdir(dp)) {
00045             char *nm = ent->d_name;
00046             for (int i = 0, v = 0;
00047                  (i < ent->d_namlen) && ('0' <= *nm) && (*nm <= '9');
00048                  i++, nm++) {
00049                 v *= 10; v += (*nm - '0');
00050             }
00051             if (i > 0 && i < ent->d_namlen && *(nm++) == '.') {
00052                 if ((!strcmp(nm, "log") && v < version) ||
00053                     (!strcmp(nm, "ckp") && v <= version)) {
00054                     // delete this file
00055                     Text fname(fullDirName);
00056                     fname += Text(ent->d_name);
00057                     try {
00058                         FS::Delete(fname);
00059                     } catch (FS::Failure) { /*SKIP*/ }
00060                 }
00061             }
00062         }
00063     }
00064     catch (...) {
00065         if (closedir(dp) < 0)
00066             throw (FS::Failure("closedir", dirName));
00067         throw;
00068     }
00069     if (closedir(dp) < 0)
00070         throw (FS::Failure("closedir", dirName));
00071 }
00072 
00073 static void* CacheS_DeleteOldLogs(void *arg) throw ()
00074 {
00075     Text *dirName = (Text *)arg;
00076     try {
00077         int version = CacheS_ReadLogVersion(*dirName);
00078         CacheS_DeleteOldLogs2(*dirName, version);
00079     } catch (FS::Error) { /*SKIP*/ }
00080     return NULL;
00081 }

Generated on Mon May 8 00:48:34 2006 for Vesta by  doxygen 1.4.2