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