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!!!
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.
This is also reproducable in KDE 3.2 RC1.
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;