mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-23 22:47:12 +01:00
Expose dump_desc() to the test suite and make things it calls mockable
This commit is contained in:
parent
726dc9acf5
commit
17ed2fed68
4 changed files with 19 additions and 5 deletions
|
@ -2013,6 +2013,16 @@ clean_name_for_stat(char *name)
|
|||
#endif
|
||||
}
|
||||
|
||||
/** Wrapper for unlink() to make it mockable for the test suite; returns 0
|
||||
* if unlinking the file succeeded, -1 and sets errno if unlinking fails.
|
||||
*/
|
||||
|
||||
MOCK_IMPL(int,
|
||||
tor_unlink,(const char *pathname))
|
||||
{
|
||||
return unlink(pathname);
|
||||
}
|
||||
|
||||
/** Return:
|
||||
* FN_ERROR if filename can't be read, is NULL, or is zero-length,
|
||||
* FN_NOENT if it doesn't exist,
|
||||
|
@ -2306,8 +2316,8 @@ check_private_dir(const char *dirname, cpd_check_t check,
|
|||
* function, and all other functions in util.c that create files, create them
|
||||
* with mode 0600.
|
||||
*/
|
||||
int
|
||||
write_str_to_file(const char *fname, const char *str, int bin)
|
||||
MOCK_IMPL(int,
|
||||
write_str_to_file,(const char *fname, const char *str, int bin))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!bin && strchr(str, '\r')) {
|
||||
|
|
|
@ -309,6 +309,8 @@ const char *stream_status_to_string(enum stream_status stream_status);
|
|||
|
||||
enum stream_status get_string_from_pipe(FILE *stream, char *buf, size_t count);
|
||||
|
||||
MOCK_DECL(int,tor_unlink,(const char *pathname));
|
||||
|
||||
/** Return values from file_status(); see that function's documentation
|
||||
* for details. */
|
||||
typedef enum { FN_ERROR, FN_NOENT, FN_FILE, FN_DIR, FN_EMPTY } file_status_t;
|
||||
|
@ -338,7 +340,8 @@ FILE *start_writing_to_stdio_file(const char *fname, int open_flags, int mode,
|
|||
FILE *fdopen_file(open_file_t *file_data);
|
||||
int finish_writing_to_file(open_file_t *file_data);
|
||||
int abort_writing_to_file(open_file_t *file_data);
|
||||
int write_str_to_file(const char *fname, const char *str, int bin);
|
||||
MOCK_DECL(int,
|
||||
write_str_to_file,(const char *fname, const char *str, int bin));
|
||||
MOCK_DECL(int,
|
||||
write_bytes_to_file,(const char *fname, const char *str, size_t len,
|
||||
int bin));
|
||||
|
|
|
@ -646,7 +646,7 @@ dump_desc_fifo_add_and_clean(char *filename, const uint8_t *digest_sha256,
|
|||
*/
|
||||
if (strcmp(tmp->filename, filename) != 0) {
|
||||
/* Delete it and adjust the length counter */
|
||||
unlink(tmp->filename);
|
||||
tor_unlink(tmp->filename);
|
||||
tor_assert(len_descs_dumped >= tmp->len);
|
||||
len_descs_dumped -= tmp->len;
|
||||
log_info(LD_DIR,
|
||||
|
@ -736,7 +736,7 @@ dump_desc_fifo_cleanup(void)
|
|||
* type *<b>type</b> to file $DATADIR/unparseable-desc. Do not write more
|
||||
* than one descriptor to disk per minute. If there is already such a
|
||||
* file in the data directory, overwrite it. */
|
||||
static void
|
||||
STATIC void
|
||||
dump_desc(const char *desc, const char *type)
|
||||
{
|
||||
tor_assert(desc);
|
||||
|
|
|
@ -92,6 +92,7 @@ STATIC int routerstatus_parse_guardfraction(const char *guardfraction_str,
|
|||
networkstatus_t *vote,
|
||||
vote_routerstatus_t *vote_rs,
|
||||
routerstatus_t *rs);
|
||||
STATIC void dump_desc(const char *desc, const char *type);
|
||||
#endif
|
||||
|
||||
#define ED_DESC_SIGNATURE_PREFIX "Tor router descriptor signature v1"
|
||||
|
|
Loading…
Add table
Reference in a new issue