kdelibs/kdelibs-4.1.3-kde#109181-kiodelete.patch
2008-10-15 12:26:02 +00:00

112 lines
4.4 KiB
Diff

Index: kio/kio/kdirlister.h
===================================================================
--- kio/kio/kdirlister.h (revision 871258)
+++ kio/kio/kdirlister.h (revision 871259)
@@ -427,6 +427,18 @@
KFileItemList itemsForDir( const KUrl& dir,
WhichItems which = FilteredItems ) const;
+ /**
+ * Return the KFileItem for the given URL, if we listed it recently
+ * and it's still in the cache - which is always the case if a directory
+ * view is currently showing this item. If not, then it might be in the
+ * cache, or it might not, in which case you get a null KFileItem.
+ * If you really need a KFileItem for this URL in all cases, then use
+ * KIO::stat() instead.
+ *
+ * @since 4.2
+ */
+ static KFileItem cachedItemForUrl(const KUrl& url);
+
Q_SIGNALS:
/**
@@ -511,7 +523,7 @@
*
* @param _fileItem the fileItem to delete
*/
- void deleteItem( const KFileItem &_fileItem ); // KDE5: remove, and port to deleteItems
+ void deleteItem( const KFileItem &_fileItem ); // KDE5: remove, and port to itemsDeleted
/**
* Signal that items have been deleted
Index: kio/kio/kdirlister.cpp
===================================================================
--- kio/kio/kdirlister.cpp (revision 871258)
+++ kio/kio/kdirlister.cpp (revision 871259)
@@ -717,7 +717,7 @@
// Maybe _u is a directory itself? (see KDirModelTest::testChmodDirectory)
DirItem* dirItem = dirItemForUrl(url);
- if (dirItem && dirItem->rootItem.url() == url) {
+ if (dirItem && !dirItem->rootItem.isNull() && dirItem->rootItem.url() == url) {
// If lister is set, check that it contains this dir
if (!lister || lister->d->lstDirs.contains(url))
return &dirItem->rootItem;
@@ -1011,7 +1011,15 @@
if ( name == "." )
{
Q_ASSERT( dir->rootItem.isNull() );
- dir->rootItem = KFileItem( *it, url, delayedMimeTypes, true );
+ // Try to reuse an existing KFileItem (if we listed the parent dir)
+ // rather than creating a new one. There are many reasons:
+ // 1) renames and permission changes to the item would have to emit the signals
+ // twice, otherwise, so that both views manage to recognize the item.
+ // 2) with kio_ftp we can only know that something is a symlink when
+ // listing the parent, so prefer that item, which has more info.
+ dir->rootItem = itemForUrl(url);
+ if (dir->rootItem.isNull())
+ dir->rootItem = KFileItem( *it, url, delayedMimeTypes, true );
foreach ( KDirLister *kdl, dirData.listersCurrentlyListing )
if ( kdl->d->rootFileItem.isNull() && kdl->d->url == url )
@@ -2515,5 +2523,10 @@
}
}
+KFileItem KDirLister::cachedItemForUrl(const KUrl& url)
+{
+ return kDirListerCache->itemForUrl(url);
+}
+
#include "kdirlister.moc"
#include "kdirlister_p.moc"
Index: kio/kio/deletejob.cpp
===================================================================
--- kio/kio/deletejob.cpp (revision 871258)
+++ kio/kio/deletejob.cpp (revision 871259)
@@ -21,6 +21,7 @@
#include "deletejob.h"
+#include "kdirlister.h"
#include "kmimetype.h"
#include "scheduler.h"
#include "kdirwatch.h"
@@ -218,6 +219,17 @@
// Stat it
state = DELETEJOB_STATE_STATING;
+ // Fast path for KFileItems in directory views
+ while(m_currentStat != m_srcList.end()) {
+ m_currentURL = (*m_currentStat);
+ KFileItem cachedItem = KDirLister::cachedItemForUrl(m_currentURL);
+ if (cachedItem.isNull())
+ break;
+ //kDebug(7007) << "Found cached info about" << m_currentURL << "isDir=" << cachedItem.isDir() << "isLink=" << cachedItem.isLink();
+ currentSourceStated(cachedItem.isDir(), cachedItem.isLink());
+ ++m_currentStat;
+ }
+
// Hook for unit test to disable the fast path.
extern bool kio_resolve_local_urls; // from copyjob.cpp, abused here to save a symbol.
if (!kio_resolve_local_urls) {
@@ -288,6 +300,7 @@
}
} else
{ // if remote - or if unlink() failed (we'll use the job's error handling in that case)
+ //kDebug(7007) << "calling file_delete on" << *it;
job = KIO::file_delete( *it, KIO::HideProgressInfo );
Scheduler::scheduleJob(job);
m_currentURL=(*it);