File kioslave_file_avoid_overwrite.diff of Package kdelibs3

------------------------------------------------------------------------
r516747 | coolo | 2006-03-08 14:41:58 +0100 (Mi, 08 Mär 2006) | 2 lines

give the right error if a file is moved over itself (on vfat)

------------------------------------------------------------------------
Index: kioslave/file/file.cc
===================================================================
--- kioslave/file/file.cc	(Revision 516746)
+++ kioslave/file/file.cc	(Revision 516747)
@@ -360,6 +360,16 @@
    return 0;
 }
 
+static bool 
+same_inode(const KDE_struct_stat &src, const KDE_struct_stat &dest)
+{
+  if (src.st_ino == dest.st_ino &&
+      src.st_dev == dest.st_dev)
+    return true;
+
+  return false;
+}
+
 void FileProtocol::put( const KURL& url, int _mode, bool _overwrite, bool _resume )
 {
     QString dest_orig = url.path();
@@ -616,6 +626,12 @@
            return;
         }
 
+	if ( same_inode( buff_dest, buff_src) ) 
+	{
+	    error( KIO::ERR_IDENTICAL_FILES, dest.path() );
+	    return;
+	}
+
         if (!_overwrite)
         {
            error( KIO::ERR_FILE_ALREADY_EXIST, dest.path() );
@@ -823,6 +839,12 @@
            return;
         }
 
+	if ( same_inode( buff_dest, buff_src) ) 
+	{
+	    error( KIO::ERR_IDENTICAL_FILES, dest.path() );
+	    return;
+	}
+
         if (!_overwrite)
         {
            error( KIO::ERR_FILE_ALREADY_EXIST, dest.path() );
openSUSE Build Service is sponsored by