From 31f4d24004fb12296bcb43984155cd57f153bf1f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 29 Apr 2010 18:56:34 +0000 Subject: [PATCH] (trunk libT) #3172 "transmission overwrites settings.json" -- fixed with kklimonda's patch for 2.00 --- libtransmission/bencode.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index 9359975dd..7c922e95c 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -11,11 +11,12 @@ */ #include -#include /* isdigit */ +#include /* isdigit() */ #include -#include /* fabs */ +#include /* PATH_MAX */ +#include /* fabs() */ #include -#include +#include /* realpath() */ #include #include /* stat() */ @@ -23,7 +24,7 @@ #include #include /* stat(), close() */ -#include /* evbuffer */ +#include /* struct evbuffer */ #include "ConvertUTF.h" @@ -1620,6 +1621,12 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename ) char * tmp; int fd; int err = 0; + char buf[PATH_MAX]; + + /* follow symlinks to find the "real" file, to make sure the temporary + * we build with mkstemp() is created on the right partition */ + if( realpath( filename, buf ) != NULL ) + filename = buf; /* if the file already exists, try to move it out of the way & keep it as a backup */ tmp = tr_strdup_printf( "%s.tmp.XXXXXX", filename );