mirror of
https://github.com/transmission/transmission.git
synced 2026-04-19 16:31:13 +01:00
(trunk libT) #3614 "Can't save benc files under uClibc 0.9.31" -- on some systems, calling unlink() on a file that doesn't exist returns 0 instead of -1 + ENOENT... so don't rely on that test. Instead, call stat() before unlink()ing the file.
This commit is contained in:
@@ -1682,10 +1682,13 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
||||
|
||||
if( write( fd, str, len ) == (ssize_t)len )
|
||||
{
|
||||
struct stat sb;
|
||||
const tr_bool already_exists = !stat( filename, &sb ) && S_ISREG( sb.st_mode );
|
||||
|
||||
tr_fsync( fd );
|
||||
tr_close_file( fd );
|
||||
|
||||
if( !unlink( filename ) || ( errno == ENOENT ) )
|
||||
if( !already_exists || !unlink( filename ) )
|
||||
{
|
||||
tr_dbg( "Renaming \"%s\" as \"%s\"", tmp, filename );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user