Bug 73440 - Konq deletes files when dragging
Summary: Konq deletes files when dragging
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: general (show other bugs)
Version: 3.1.4
Platform: Mandrake RPMs Linux
: NOR grave
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-25 01:41 UTC by Christoph Eckert
Modified: 2005-08-23 06:24 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Eckert 2004-01-25 01:41:35 UTC
Version:           3.1.4 (using KDE KDE 3.1.4)
Installed from:    Mandrake RPMs
OS:          Linux

OK, this is some of exceptionnel, but it did delete my file, so here it is:

* Create two temporary directories
* open both in two Konqu windows
* put a copy of any file into one of the directories
* drag the file to the second directory
* choose 'link here'
* This was wrong; you wanted to create a copy. So, please drag again from the first to the second folder
* this time, choose copy here
* you get promted what to do (rename, overwrite etc.). Choose Overwrite, because you want to overwrite the existing symlink with the file itself

=> this results in setting the original file to 0Bytes :(

OK, this is an action which is most probably not oerformed very often, but it would be fine if the original file wouldn't be deleted. Can you do something to prevent any other person loosing the work of hours? If so, please do it.

Anyway, thanks for Konq and KDE in general!!!
Comment 1 kdebugs 2004-01-25 23:22:20 UTC
Same happens in version 3.1.3.

As said above, this action is not common but has the potential of wiping a lot ot work :(

Please consider as higher priority.
Comment 2 Dik Takken 2004-01-31 13:55:31 UTC
This is also reproducable in KDE 3.2 RC1.
Comment 3 Dawit Alemayehu 2004-02-15 00:52:05 UTC
CVS commit by adawit: 

- Remove redundant KDE_stat call in FileProtocol::stat.

- When copying or moving if the source exists as a symlink at the destination,
  remove it first to avoid the scenario where the symlink is pointing to the 
  current source. Fixes BR# 73440.

CCMAIL: 73440-done@bugs.kde.org


  M +32 -18    file.cc   1.146


--- kdelibs/kioslave/file/file.cc  #1.145:1.146
@@ -133,4 +133,7 @@ void FileProtocol::mkdir( const KURL& ur
 {
     QCString _path( QFile::encodeName(url.path()));
+    
+    kdDebug(7101) << "mkdir(): " << _path << ", permission = " << permissions << endl;
+        
     KDE_struct_stat buff;
     if ( KDE_stat( _path.data(), &buff ) == -1 ) {
@@ -278,5 +281,5 @@ void FileProtocol::put( const KURL& url,
     QCString _dest_orig( QFile::encodeName(dest_orig));
 
-    kdDebug(7101) << "Put " << dest_orig << endl;
+    kdDebug(7101) << "put(): " << dest_orig << ", mode=" << _mode << endl;
 
     QString dest_part( dest_orig );
@@ -285,5 +288,5 @@ void FileProtocol::put( const KURL& url,
 
     KDE_struct_stat buff_orig;
-    bool orig_exists = (KDE_stat( _dest_orig.data(), &buff_orig ) != -1);
+    bool orig_exists = (KDE_lstat( _dest_orig.data(), &buff_orig ) != -1);
     bool part_exists = false;
     bool bMarkPartial = config()->readBoolEntry("MarkPartial", true);
@@ -443,4 +446,10 @@ void FileProtocol::put( const KURL& url,
     if ( bMarkPartial )
     {
+        // If the original URL is a symlink and we were asked to overwrite it,
+        // remove the symlink first. This ensures that we do not overwrite the
+        // current source if the symlink points to it.
+        if( _overwrite && S_ISLNK( buff_orig.st_mode ) )
+          remove( _dest_orig.data() );
+        
         if ( ::rename( _dest.data(), _dest_orig.data() ) )
         {
@@ -470,4 +479,6 @@ void FileProtocol::copy( const KURL &src
                          int _mode, bool _overwrite )
 {
+    kdDebug(7101) << "copy(): " << src << " -> " << dest << ", mode=" << _mode << endl;
+        
     QCString _src( QFile::encodeName(src.path()));
     QCString _dest( QFile::encodeName(dest.path()));
@@ -491,5 +502,5 @@ void FileProtocol::copy( const KURL &src
 
     KDE_struct_stat buff_dest;
-    bool dest_exists = ( KDE_stat( _dest.data(), &buff_dest ) != -1 );
+    bool dest_exists = ( KDE_lstat( _dest.data(), &buff_dest ) != -1 );
     if ( dest_exists )
     {
@@ -505,4 +516,13 @@ void FileProtocol::copy( const KURL &src
            return;
         }
+        
+        // If the destination is a symlink and overwrite is TRUE,
+        // remove the symlink first to prevent the scenario where 
+        // the symlink actually points to current source!
+        if (_overwrite && S_ISLNK(buff_dest.st_mode))
+        {
+            kdDebug(7101) << "copy(): LINK DESTINATION" << endl;
+            remove( _dest.data() );
+        }
     }
 
@@ -824,5 +844,5 @@ bool FileProtocol::createUDSEntry( const
         }
     } else {
-        kdWarning() << "lstat didn't work on " << path.data() << endl;
+        // kdWarning() << "lstat didn't work on " << path.data() << endl;
         return false;
     }
@@ -902,9 +922,4 @@ void FileProtocol::stat( const KURL & ur
      */
     QCString _path( QFile::encodeName(url.path(-1)));
-    KDE_struct_stat buff;
-    if ( KDE_lstat( _path.data(), &buff ) == -1 ) {
-        error( KIO::ERR_DOES_NOT_EXIST, url.path(-1) );
-        return;
-    }
 
     QString sDetails = metaData(QString::fromLatin1("details"));
@@ -915,5 +930,4 @@ void FileProtocol::stat( const KURL & ur
     if ( !createUDSEntry( url.fileName(), _path, entry, details ) )
     {
-        // Should never happen
         error( KIO::ERR_DOES_NOT_EXIST, url.path(-1) );
         return;