[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r11918: Eventually delete the obsolete cached-routers and cached-rou (in tor/trunk: . src/or)
Author: nickm
Date: 2007-10-13 20:13:06 -0400 (Sat, 13 Oct 2007)
New Revision: 11918
Modified:
tor/trunk/
tor/trunk/ChangeLog
tor/trunk/src/or/config.c
tor/trunk/src/or/or.h
tor/trunk/src/or/routerlist.c
Log:
r15750@catbus: nickm | 2007-10-13 20:06:47 -0400
Eventually delete the obsolete cached-routers and cached-routers.new files, so they don't sit around on disk forever.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r15750] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2007-10-14 00:13:04 UTC (rev 11917)
+++ tor/trunk/ChangeLog 2007-10-14 00:13:06 UTC (rev 11918)
@@ -6,6 +6,11 @@
it. Extra descriptors without any real changes are dropped by the
authorities, and can screw up our "publish every 18 hours" schedule.
+ o Minor features:
+ - If we find a cached-routers file that's been sitting around for more
+ than 28 days unmodified, then most likely it's a leftover from when we
+ upgraded to 0.2.0.8-alpha. Remove it. It has no good routers anyway.
+
o Code simplifications and refactoring:
- Remove support for the old bw_accounting file: we've been storing
bandwidth accounting information in the state file since 0.1.2.5-alpha.
Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c 2007-10-14 00:13:04 UTC (rev 11917)
+++ tor/trunk/src/or/config.c 2007-10-14 00:13:06 UTC (rev 11918)
@@ -4526,6 +4526,23 @@
return 0;
}
+/** Given a file name check to see whether the file exists but has not been
+ * modified for a very long time. If so, remove it. */
+void
+remove_file_if_very_old(const char *fname, time_t now)
+{
+#define VERY_OLD_FILE_AGE (28*24*60*60)
+ struct stat st;
+
+ if (stat(fname, &st)==0 && st.st_mtime < now-VERY_OLD_FILE_AGE) {
+ char buf[ISO_TIME_LEN+1];
+ format_local_iso_time(buf, st.st_mtime);
+ log_notice(LD_GENERAL, "Obsolete file %s hasn't been modified since %s. "
+ "Removing it.", fname, buf);
+ unlink(fname);
+ }
+}
+
/** Helper to implement GETINFO functions about configuration variables (not
* their values). Given a "config/names" question, set *<b>answer</b> to a
* new string describing the supported configuration variables and their
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2007-10-14 00:13:04 UTC (rev 11917)
+++ tor/trunk/src/or/or.h 2007-10-14 00:13:06 UTC (rev 11918)
@@ -2542,6 +2542,7 @@
void assert_connection_ok(connection_t *conn, time_t now);
int connection_or_nonopen_was_started_here(or_connection_t *conn);
void connection_dump_buffer_mem_stats(int severity);
+void remove_file_if_very_old(const char *fname, time_t now);
/********************************* connection_edge.c *************************/
Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c 2007-10-14 00:13:04 UTC (rev 11917)
+++ tor/trunk/src/or/routerlist.c 2007-10-14 00:13:06 UTC (rev 11918)
@@ -601,6 +601,7 @@
struct stat st;
int read_from_old_location = 0;
int extrainfo = (store->type == EXTRAINFO_STORE);
+ time_t now = time(NULL);
store->journal_len = store->store_len = 0;
tor_snprintf(fname, fname_len, "%s"PATH_SEPARATOR"%s",
@@ -623,6 +624,9 @@
if ((store->mmap = tor_mmap_file(altname)))
read_from_old_location = 1;
}
+ if (altname && !read_from_old_location) {
+ remove_file_if_very_old(altname, now);
+ }
if (store->mmap) {
store->store_len = store->mmap->size;
if (extrainfo)
@@ -639,10 +643,13 @@
options->DataDirectory, store->fname_base);
if (file_status(fname) == FN_FILE)
contents = read_file_to_str(fname, RFTS_BIN|RFTS_IGNORE_MISSING, &st);
- if (!contents && read_from_old_location) {
+ if (read_from_old_location) {
tor_snprintf(altname, fname_len, "%s"PATH_SEPARATOR"%s.new",
options->DataDirectory, store->fname_alt_base);
- contents = read_file_to_str(altname, RFTS_BIN|RFTS_IGNORE_MISSING, &st);
+ if (!contents)
+ contents = read_file_to_str(altname, RFTS_BIN|RFTS_IGNORE_MISSING, &st);
+ else
+ remove_file_if_very_old(altname, now);
}
if (contents) {
if (extrainfo)