Changeset 11819


Ignore:
Timestamp:
Feb 3, 2011, 12:48:05 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) #3975: "tr_bencToFile() contains unnecessary calls to stat() and unlink()" -- fixed.

When saving a tr_benc object to disk at $dst, bencode.c saves it to a tmp file in the same directory as $dst, unlinks $dst if it exists, and then renames $tmp as $dst. This commit removes the middle step, which is unnecessary because rename() has guarantees about atomically overwriting $dst.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r11816 r11819  
    17081708        else
    17091709        {
    1710             struct stat sb;
    1711             const tr_bool already_exists = !stat( filename, &sb ) && S_ISREG( sb.st_mode );
    1712 
    17131710            tr_fsync( fd );
    17141711            tr_close_file( fd );
    17151712
    1716             if( !already_exists || !unlink( filename ) )
     1713            if( !rename( tmp, filename ) )
    17171714            {
    1718                 if( !rename( tmp, filename ) )
    1719                 {
    1720                     tr_inf( _( "Saved \"%s\"" ), filename );
    1721                 }
    1722                 else
    1723                 {
    1724                     err = errno;
    1725                     tr_err( _( "Couldn't save file \"%1$s\": %2$s" ), filename, tr_strerror( err ) );
    1726                     unlink( tmp );
    1727                 }
     1715                tr_inf( _( "Saved \"%s\"" ), filename );
    17281716            }
    17291717            else
Note: See TracChangeset for help on using the changeset viewer.