mirror of
https://github.com/transmission/transmission
synced 2025-02-22 14:10:34 +00:00
mikedld patch: 4160-05b-file-fmt.patch
This commit is contained in:
parent
a59d3392b6
commit
01196c8c4f
5 changed files with 53 additions and 54 deletions
|
@ -302,14 +302,15 @@ compareAddressRangesByFirstAddress (const void * va, const void * vb)
|
|||
int
|
||||
tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename)
|
||||
{
|
||||
FILE * in;
|
||||
FILE * out;
|
||||
tr_sys_file_t in;
|
||||
tr_sys_file_t out;
|
||||
int inCount = 0;
|
||||
char line[2048];
|
||||
const char * err_fmt = _("Couldn't read \"%1$s\": %2$s");
|
||||
struct tr_ipv4_range * ranges = NULL;
|
||||
size_t ranges_alloc = 0;
|
||||
size_t ranges_count = 0;
|
||||
tr_error * error = NULL;
|
||||
|
||||
if (!filename)
|
||||
{
|
||||
|
@ -317,35 +318,34 @@ tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
in = fopen (filename, "rb");
|
||||
if (in == NULL)
|
||||
in = tr_sys_file_open (filename, TR_SYS_FILE_READ, 0, &error);
|
||||
if (in == TR_BAD_SYS_FILE)
|
||||
{
|
||||
tr_logAddError (err_fmt, filename, tr_strerror (errno));
|
||||
tr_logAddError (err_fmt, filename, error->message);
|
||||
tr_error_free (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
blocklistClose (b);
|
||||
|
||||
out = fopen (b->filename, "wb+");
|
||||
if (out == NULL)
|
||||
out = tr_sys_file_open (b->filename,
|
||||
TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE,
|
||||
0666, &error);
|
||||
if (out == TR_BAD_SYS_FILE)
|
||||
{
|
||||
tr_logAddError (err_fmt, b->filename, tr_strerror (errno));
|
||||
fclose (in);
|
||||
tr_logAddError (err_fmt, b->filename, error->message);
|
||||
tr_error_free (error);
|
||||
tr_sys_file_close (in, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* load the rules into memory */
|
||||
while (fgets (line, sizeof (line), in) != NULL)
|
||||
while (tr_sys_file_read_line (in, line, sizeof (line), NULL))
|
||||
{
|
||||
char * walk;
|
||||
struct tr_ipv4_range range;
|
||||
|
||||
++inCount;
|
||||
|
||||
/* zap the linefeed */
|
||||
if ((walk = strchr (line, '\r'))) *walk = '\0';
|
||||
if ((walk = strchr (line, '\n'))) *walk = '\0';
|
||||
|
||||
if (!parseLine (line, &range))
|
||||
{
|
||||
/* don't try to display the actual lines - it causes issues */
|
||||
|
@ -397,9 +397,10 @@ tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (fwrite (ranges, sizeof (struct tr_ipv4_range), ranges_count, out) != ranges_count)
|
||||
if (!tr_sys_file_write (out, ranges, sizeof (struct tr_ipv4_range) * ranges_count, NULL, &error))
|
||||
{
|
||||
tr_logAddError (_("Couldn't save file \"%1$s\": %2$s"), b->filename, tr_strerror (errno));
|
||||
tr_logAddError (_("Couldn't save file \"%1$s\": %2$s"), b->filename, error->message);
|
||||
tr_error_free (error);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -409,8 +410,8 @@ tr_blocklistFileSetContent (tr_blocklistFile * b, const char * filename)
|
|||
}
|
||||
|
||||
tr_free (ranges);
|
||||
fclose (out);
|
||||
fclose (in);
|
||||
tr_sys_file_close (out, NULL);
|
||||
tr_sys_file_close (in, NULL);
|
||||
|
||||
blocklistLoad (b);
|
||||
|
||||
|
|
|
@ -58,11 +58,11 @@ getMessageLock (void)
|
|||
return l;
|
||||
}
|
||||
|
||||
void*
|
||||
tr_sys_file_t
|
||||
tr_logGetFile (void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
static FILE * file = NULL;
|
||||
static tr_sys_file_t file = TR_BAD_SYS_FILE;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
|
@ -75,15 +75,11 @@ tr_logGetFile (void)
|
|||
switch (fd)
|
||||
{
|
||||
case 1:
|
||||
file = stdout;
|
||||
file = tr_sys_file_get_std (TR_STD_SYS_FILE_OUT, NULL);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
file = stderr;
|
||||
break;
|
||||
|
||||
default:
|
||||
file = NULL;
|
||||
file = tr_sys_file_get_std (TR_STD_SYS_FILE_ERR, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -136,9 +132,9 @@ tr_logFreeQueue (tr_log_message * list)
|
|||
while (NULL != list)
|
||||
{
|
||||
next = list->next;
|
||||
free (list->message);
|
||||
free (list->name);
|
||||
free (list);
|
||||
tr_free (list->message);
|
||||
tr_free (list->name);
|
||||
tr_free (list);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +169,7 @@ tr_logGetDeepEnabled (void)
|
|||
static int8_t deepLoggingIsActive = -1;
|
||||
|
||||
if (deepLoggingIsActive < 0)
|
||||
deepLoggingIsActive = IsDebuggerPresent () || (tr_logGetFile ()!=NULL);
|
||||
deepLoggingIsActive = IsDebuggerPresent () || (tr_logGetFile () != TR_BAD_SYS_FILE);
|
||||
|
||||
return deepLoggingIsActive != 0;
|
||||
}
|
||||
|
@ -185,8 +181,8 @@ tr_logAddDeep (const char * file,
|
|||
const char * fmt,
|
||||
...)
|
||||
{
|
||||
FILE * fp = tr_logGetFile ();
|
||||
if (fp || IsDebuggerPresent ())
|
||||
const tr_sys_file_t fp = tr_logGetFile ();
|
||||
if (fp != TR_BAD_SYS_FILE || IsDebuggerPresent ())
|
||||
{
|
||||
va_list args;
|
||||
char timestr[64];
|
||||
|
@ -201,12 +197,13 @@ tr_logAddDeep (const char * file,
|
|||
va_start (args, fmt);
|
||||
evbuffer_add_vprintf (buf, fmt, args);
|
||||
va_end (args);
|
||||
evbuffer_add_printf (buf, " (%s:%d)\n", base, line);
|
||||
evbuffer_add_printf (buf, " (%s:%d)", base, line);
|
||||
/* FIXME (libevent2) ifdef this out for nonwindows platforms */
|
||||
message = evbuffer_free_to_str (buf);
|
||||
OutputDebugStringA (message);
|
||||
if (fp)
|
||||
fputs (message, fp);
|
||||
OutputDebugStringA (TR_NATIVE_EOL_STR);
|
||||
if (fp != TR_BAD_SYS_FILE)
|
||||
tr_sys_file_write_line (fp, message, NULL);
|
||||
|
||||
tr_free (message);
|
||||
tr_free (base);
|
||||
|
@ -267,20 +264,20 @@ tr_logAddMessage (const char * file,
|
|||
}
|
||||
else
|
||||
{
|
||||
FILE * fp;
|
||||
tr_sys_file_t fp;
|
||||
char timestr[64];
|
||||
|
||||
fp = tr_logGetFile ();
|
||||
if (fp == NULL)
|
||||
fp = stderr;
|
||||
if (fp == TR_BAD_SYS_FILE)
|
||||
fp = tr_sys_file_get_std (TR_STD_SYS_FILE_ERR, NULL);
|
||||
|
||||
tr_logGetTimeStr (timestr, sizeof (timestr));
|
||||
|
||||
if (name)
|
||||
fprintf (fp, "[%s] %s: %s\n", timestr, name, buf);
|
||||
tr_sys_file_write_fmt (fp, "[%s] %s: %s" TR_NATIVE_EOL_STR, NULL, timestr, name, buf);
|
||||
else
|
||||
fprintf (fp, "[%s] %s\n", timestr, buf);
|
||||
fflush (fp);
|
||||
tr_sys_file_write_fmt (fp, "[%s] %s" TR_NATIVE_EOL_STR, NULL, timestr, buf);
|
||||
tr_sys_file_flush (fp, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#define TR_LOG_H 1
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
#include "file.h" /* tr_sys_file_t */
|
||||
#include "utils.h" /* TR_GNUC_PRINTF, TR_GNUC_NONNULL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -107,7 +109,7 @@ void tr_logAddMessage (const char * file,
|
|||
|
||||
|
||||
|
||||
void* tr_logGetFile (void);
|
||||
tr_sys_file_t tr_logGetFile (void);
|
||||
|
||||
/** @brief return true if deep logging has been enabled by the user; false otherwise */
|
||||
bool tr_logGetDeepEnabled (void);
|
||||
|
|
|
@ -282,9 +282,9 @@ myDebug (const char * file, int line,
|
|||
const struct tr_peerMsgs * msgs,
|
||||
const char * fmt, ...)
|
||||
{
|
||||
FILE * fp = tr_logGetFile ();
|
||||
const tr_sys_file_t fp = tr_logGetFile ();
|
||||
|
||||
if (fp)
|
||||
if (fp != TR_BAD_SYS_FILE)
|
||||
{
|
||||
va_list args;
|
||||
char timestr[64];
|
||||
|
@ -300,10 +300,10 @@ myDebug (const char * file, int line,
|
|||
va_start (args, fmt);
|
||||
evbuffer_add_vprintf (buf, fmt, args);
|
||||
va_end (args);
|
||||
evbuffer_add_printf (buf, " (%s:%d)\n", base, line);
|
||||
evbuffer_add_printf (buf, " (%s:%d)", base, line);
|
||||
|
||||
message = evbuffer_free_to_str (buf);
|
||||
fputs (message, fp);
|
||||
tr_sys_file_write_line (fp, message, NULL);
|
||||
|
||||
tr_free (base);
|
||||
tr_free (message);
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
/* posix */
|
||||
#include <signal.h> /* sig_atomic_t */
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h> /* close () */
|
||||
#ifdef _WIN32
|
||||
#include <inttypes.h>
|
||||
#define _WIN32_WINNT 0x0501 /* freeaddrinfo (),getaddrinfo (),getnameinfo () */
|
||||
|
@ -51,6 +50,7 @@
|
|||
/* libT */
|
||||
#include "transmission.h"
|
||||
#include "crypto.h"
|
||||
#include "file.h"
|
||||
#include "log.h"
|
||||
#include "net.h"
|
||||
#include "peer-mgr.h" /* tr_peerMgrCompactToPex () */
|
||||
|
@ -195,22 +195,21 @@ dht_bootstrap (void *closure)
|
|||
|
||||
if (!bootstrap_done (cl->session, 0)) {
|
||||
char *bootstrap_file;
|
||||
FILE *f = NULL;
|
||||
tr_sys_file_t f = TR_BAD_SYS_FILE;
|
||||
|
||||
bootstrap_file =
|
||||
tr_buildPath (cl->session->configDir, "dht.bootstrap", NULL);
|
||||
|
||||
if (bootstrap_file)
|
||||
f = fopen (bootstrap_file, "rb");
|
||||
if (f != NULL) {
|
||||
f = tr_sys_file_open (bootstrap_file, TR_SYS_FILE_READ, 0, NULL);
|
||||
if (f != TR_BAD_SYS_FILE) {
|
||||
tr_logAddNamedInfo ("DHT", "Attempting manual bootstrap");
|
||||
for (;;) {
|
||||
char buf[201];
|
||||
char *p;
|
||||
int port = 0;
|
||||
|
||||
p = fgets (buf, 200, f);
|
||||
if (p == NULL)
|
||||
if (!tr_sys_file_read_line (f, buf, 200, NULL))
|
||||
break;
|
||||
|
||||
p = memchr (buf, ' ', strlen (buf));
|
||||
|
@ -228,7 +227,7 @@ dht_bootstrap (void *closure)
|
|||
if (bootstrap_done (cl->session, 0))
|
||||
break;
|
||||
}
|
||||
fclose (f);
|
||||
tr_sys_file_close (f, NULL);
|
||||
}
|
||||
|
||||
tr_free (bootstrap_file);
|
||||
|
|
Loading…
Reference in a new issue