(trunk gtk) #3844 "error popup when adding a relative path" -- fixed. initial patch by ijuxda.
This commit is contained in:
parent
a297cd328a
commit
81cb2276c8
|
@ -15,6 +15,9 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/utils.h> /* tr_is_same_file() */
|
||||
|
||||
#include "add-dialog.h"
|
||||
#include "conf.h"
|
||||
#include "file-list.h"
|
||||
|
@ -187,7 +190,7 @@ sourceChanged( GtkFileChooserButton * b, gpointer gdata )
|
|||
int new_file = 0;
|
||||
tr_torrent * torrent;
|
||||
|
||||
if( filename && ( !data->filename || strcmp( filename, data->filename ) ) )
|
||||
if( filename && ( !data->filename || !tr_is_same_file( filename, data->filename ) ) )
|
||||
{
|
||||
g_free( data->filename );
|
||||
data->filename = g_strdup( filename );
|
||||
|
@ -221,7 +224,7 @@ downloadDirChanged( GtkFileChooserButton * b, gpointer gdata )
|
|||
struct AddData * data = gdata;
|
||||
char * fname = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );
|
||||
|
||||
if( fname && ( !data->downloadDir || strcmp( fname, data->downloadDir ) ) )
|
||||
if( fname && ( !data->downloadDir || !tr_is_same_file( fname, data->downloadDir ) ) )
|
||||
{
|
||||
g_free( data->downloadDir );
|
||||
data->downloadDir = g_strdup( fname );
|
||||
|
|
|
@ -2781,28 +2781,6 @@ struct LocationData
|
|||
tr_torrent * tor;
|
||||
};
|
||||
|
||||
static tr_bool
|
||||
isSameLocation( const char * path1, const char * path2 )
|
||||
{
|
||||
struct stat s1, s2;
|
||||
const int err1 = stat( path1, &s1 );
|
||||
const int err2 = stat( path2, &s2 );
|
||||
|
||||
if( !err1 && !err2 ) {
|
||||
tr_dbg( "path1 dev:inode is %"PRIu64":%"PRIu64"; "
|
||||
"path2 dev:inode is %"PRIu64":%"PRIu64,
|
||||
(uint64_t)s1.st_dev, (uint64_t)s1.st_ino,
|
||||
(uint64_t)s2.st_dev, (uint64_t)s2.st_ino );
|
||||
return ( s1.st_dev == s2.st_dev )
|
||||
&& ( s1.st_ino == s2.st_ino );
|
||||
}
|
||||
|
||||
/* either one, or the other, or both don't exist... */
|
||||
tr_dbg( "stat(%s) returned %d\n", path1, err1 );
|
||||
tr_dbg( "stat(%s) returned %d\n", path2, err2 );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
setLocation( void * vdata )
|
||||
{
|
||||
|
@ -2820,7 +2798,7 @@ setLocation( void * vdata )
|
|||
|
||||
tr_mkdirp( location, 0777 );
|
||||
|
||||
if( !isSameLocation( location, tor->currentDir ) )
|
||||
if( !tr_is_same_file( location, tor->currentDir ) )
|
||||
{
|
||||
tr_file_index_t i;
|
||||
|
||||
|
|
|
@ -1587,6 +1587,17 @@ tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed )
|
|||
return 0;
|
||||
}
|
||||
|
||||
tr_bool
|
||||
tr_is_same_file( const char * filename1, const char * filename2 )
|
||||
{
|
||||
struct stat sb1, sb2;
|
||||
|
||||
return !stat( filename1, &sb1 )
|
||||
&& !stat( filename2, &sb2 )
|
||||
&& ( sb1.st_dev == sb2.st_dev )
|
||||
&& ( sb1.st_ino == sb2.st_ino );
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
|
|
@ -517,6 +517,9 @@ struct tm * tr_localtime_r( const time_t *_clock, struct tm *_result );
|
|||
int tr_moveFile( const char * oldpath, const char * newpath,
|
||||
tr_bool * renamed ) TR_GNUC_NONNULL(1,2);
|
||||
|
||||
/** @brief Test to see if the two filenames point to the same file. */
|
||||
tr_bool tr_is_same_file( const char * filename1, const char * filename2 );
|
||||
|
||||
/** @brief convenience function to remove an item from an array */
|
||||
void tr_removeElementFromArray( void * array,
|
||||
unsigned int index_to_remove,
|
||||
|
|
Loading…
Reference in New Issue