(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:
Charles Kerr
2010-10-11 21:27:31 +00:00
parent 8d15c48a3f
commit 0cf643f8c3

View File

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