Bug 233181 - organise files fails if source == dest
Summary: organise files fails if source == dest
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: Collections/Local (show other bugs)
Version: 2.3-GIT
Platform: Ubuntu Linux
: HI normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-03 18:36 UTC by kreykrey
Modified: 2012-08-19 16:53 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 2.3.1


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kreykrey 2010-04-03 18:36:12 UTC
Version:           2.3.0. (using KDE 4.4.1)
OS:                Linux
Installed from:    Ubuntu Packages

When I click "Organise Files" on a single file and choose a pattern such that source == destination, amarok fails to do anything, i.e. bar at the bottom says: "Moving files: 0%"
If there are several files on the queue it will fail to proceed.

Also
If source != destination, the file is moved, and _after_ that I am asked whether or not I really want to delete the file. (wtf?) Choosing "Delete" or "Cancel" yield the same result: nothing happens.
Comment 1 Kuba Serafinowski 2010-04-03 19:13:22 UTC
Confirmed, happens here too.
Comment 2 Casey Link 2010-04-04 00:56:59 UTC
commit b99209d8a021275614f8ab7847cd3e457a2181c3
Author: Casey Link <unnamedrambler@gmail.com>
Date:   Sat Apr 3 13:33:48 2010 -0400

    Fix bug that stalled an organize operation when src == dest
    BUG: 233181

diff --git a/src/core-impl/collections/sqlcollection/SqlCollectionLocation.cpp b/src/core-impl/collections/sqlcollection/SqlCollectionLocation.cpp
index 851cd51..1ac258f 100644
--- a/src/core-impl/collections/sqlcollection/SqlCollectionLocation.cpp
+++ b/src/core-impl/collections/sqlcollection/SqlCollectionLocation.cpp
@@ -523,11 +523,15 @@ bool SqlCollectionLocation::startNextJob()
                 return true; // Attempt to copy/move the next item in m_sources
             }
         }
-        if( src == dest) {
-        //no changes, so leave the database alone, and don't erase anything
-            return true; // Attempt to copy/move the next item in m_sources
+        if( src.equals( dest ) )
+        {
+            debug() << "move to itself found";
+            source()->transferSuccessful( track );
+            m_transferjob->slotJobFinished( 0 );
+            if( m_sources.isEmpty() )
+                return false;
+            return true;
         }
-        //we should only move it directly if we're moving within the same collection
         else if( isGoingToRemoveSources() && source()->collection() == collection() )
         {
             debug() << "moving!";
@@ -535,7 +539,7 @@ bool SqlCollectionLocation::startNextJob()
         }
         else
         {
-        //later on in the case that remove is called, the file will be deleted because we didn't apply moveByDestination to the track
+            //later on in the case that remove is called, the file will be deleted because we didn't apply moveByDestination to the track
             job = KIO::file_copy( src, dest, -1, flags );
         }
         if( job )   //just to be safe
@@ -629,15 +633,16 @@ void TransferJob::doWork()
     setProcessedAmount( KJob::Files, 0 );
     if( !m_location->startNextJob() )
     {
-        if( hasSubjobs() )
+        if( !hasSubjobs() )
             emitResult();
     }
 }
 
 void TransferJob::slotJobFinished( KJob* job )
 {
-    Q_UNUSED( job );
     DEBUG_BLOCK
+    if( job )
+        removeSubjob( job );
     if( m_killed )
     {
         debug() << "slotJobFinished entered, but it should be killed!";
@@ -648,9 +653,12 @@ void TransferJob::slotJobFinished( KJob* job )
     debug() << "processed" << processedAmount( KJob::Files ) << " totalAmount" << totalAmount( KJob::Files );
     if( !m_location->startNextJob() )
     {
+        debug() << "sources empty";
         // don't quit if there are still subjobs
-        if( hasSubjobs() )
+        if( !hasSubjobs() )
             emitResult();
+        else
+            debug() << "have subjobs";
     }
 }
 
diff --git a/src/core-impl/collections/sqlcollection/SqlCollectionLocation.h b/src/core-impl/collections/sqlcollection/SqlCollectionLocation.h
index 149423a..cbfe9b7 100644
--- a/src/core-impl/collections/sqlcollection/SqlCollectionLocation.h
+++ b/src/core-impl/collections/sqlcollection/SqlCollectionLocation.h
@@ -46,14 +46,13 @@ class TransferJob : public KCompositeJob
     virtual bool addSubjob( KJob* job );
 
     void emitInfo( const QString &message );
-
-    protected slots:
-        void doWork();
-
+    public slots:
         /**
          * A move or copy job finished
          */
         void slotJobFinished( KJob *job );
+    protected slots:
+        void doWork();
     protected:
         virtual bool doKill();
     private: