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.


svn:r11918
This commit is contained in:
Nick Mathewson 2007-10-14 00:13:06 +00:00
parent 1b45314775
commit 09dfe31ff4
4 changed files with 32 additions and 2 deletions

View File

@ -6,6 +6,11 @@ Changes in version 0.2.0.9-alpha - 2007-10-??
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.

View File

@ -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

View File

@ -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 *************************/

View File

@ -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);
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)