00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00055 Text fname(fullDirName);
00056 fname += Text(ent->d_name);
00057 try {
00058 FS::Delete(fname);
00059 } catch (FS::Failure) { }
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) { }
00080 return NULL;
00081 }