summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
Diffstat (limited to 'src/or')
-rw-r--r--src/or/config.c17
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/routerlist.c11
3 files changed, 27 insertions, 2 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 4b548e3392..0bf88b2e44 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -4526,6 +4526,23 @@ or_state_save(time_t now)
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
diff --git a/src/or/or.h b/src/or/or.h
index c81f5e0a83..002d9811db 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2542,6 +2542,7 @@ char *alloc_http_authenticator(const char *authenticator);
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 *************************/
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index d4e692cad7..cb511446ef 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -601,6 +601,7 @@ router_reload_router_list_impl(desc_store_t *store)
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 @@ router_reload_router_list_impl(desc_store_t *store)
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 @@ router_reload_router_list_impl(desc_store_t *store)
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)