[tor-bugs] #4282 [Tor Relay]: Extract common "make private stats dir" code from rephist.c, geoip.c

Tor Bug Tracker & Wiki torproject-admin at torproject.org
Fri Oct 21 14:22:24 UTC 2011


#4282: Extract common "make private stats dir" code from rephist.c, geoip.c
-----------------------+----------------------------------------------------
 Reporter:  nickm      |          Owner:     
     Type:  defect     |         Status:  new
 Priority:  normal     |      Milestone:     
Component:  Tor Relay  |        Version:     
 Keywords:             |         Parent:     
   Points:             |   Actualpoints:     
-----------------------+----------------------------------------------------
 In several places in rephist.c and geoip.c, we do:
 {{{
   /* Try to write to disk. */
   statsdir = get_datadir_fname("stats");
   if (check_private_dir(statsdir, CPD_CREATE, get_options()->User) < 0) {
     log_warn(LD_HIST, "Unable to create stats/ directory!");
     goto done;
   }
   filename = get_datadir_fname2("stats", "buffer-stats");
   if (write_str_to_file(filename, str, 0) < 0)
     log_warn(LD_HIST, "Unable to write buffer stats to disk!");
 }}}

 Duplicated code is stupid.  Some or all of this should get extracted into
 a new function or two.  I'd suggest a function to "create the datadir and
 a subdirectory of the datadir as needed" and another function to write a
 file to a subdirectory of the datadir, creating that subdirectory as
 needed.

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/4282>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list