[SCM] Kaboom - Debian KDE 3->4 migration tool branch, master, updated. 72b3d638adec11878c511df5d937c2f29967a837

George Kiagiadakis gkiagia-guest at alioth.debian.org
Wed Feb 18 21:54:50 UTC 2009


The following commit has been merged in the master branch:
commit 72b3d638adec11878c511df5d937c2f29967a837
Author: George Kiagiadakis <gkiagia at users.sourceforge.net>
Date:   Wed Feb 18 23:52:59 2009 +0200

    Merge the functionality of mergeDirs() back to recursiveCpDir() and use flags to define behavior.

diff --git a/diroperations/diroperations.cpp b/diroperations/diroperations.cpp
index 13a76b7..992f5ea 100644
--- a/diroperations/diroperations.cpp
+++ b/diroperations/diroperations.cpp
@@ -94,7 +94,7 @@ qint64 calculateDirSize(const QString & dir, ProgressDialogInterface *pd)
     return totalSize;
 }
 
-void recursiveCpDir(const QString & sourcePath, const QString & destPath, bool force, ProgressDialogInterface *pd)
+void recursiveCpDir(const QString & sourcePath, const QString & destPath, CopyOptions options, ProgressDialogInterface *pd)
 {
     QDir source(sourcePath);
     if ( !source.exists() )
@@ -102,90 +102,11 @@ void recursiveCpDir(const QString & sourcePath, const QString & destPath, bool f
 
     QDir dest(destPath);
     if ( dest.exists() ) {
-        if ( force )
+        if ( options & RemoveDestination )
             recursiveRmDir(destPath, pd);
-        else
+        else if ( !(options & OverWrite) )
             throw Exception(Exception::FileOrDirectoryExists, destPath);
-    }
-
-    QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System | QDir::CaseSensitive;
-    QFileInfoList currentList = source.entryInfoList( filters, QDir::DirsLast );
-    QFileInfo currentItem;
-    QStack<QFileInfoList> stack;
-    QString currentName;
-    qint64 bytesCopied = 0;
-
-    if ( pd ) {
-        pd->setMaximum(calculateDirSize(sourcePath, pd));
-        pd->setLabelText(QObject::tr("Copying files..."));
-    }
-
-    dest.mkdir(dest.absolutePath());
-
-    while(1)
-    {
-        if ( !currentList.isEmpty() )
-        {
-            currentItem = currentList.takeFirst();
-            currentName = currentItem.fileName();
-
-            if ( currentItem.isSymLink() )
-            {
-                if ( !QFile::link( relativeSymLinkTarget(source.absoluteFilePath(currentName)),
-                                    dest.absoluteFilePath(currentName) ) )
-                    throw Exception(Exception::CopyFail, currentItem.absoluteFilePath());
-            }
-            else if ( currentItem.isDir() )
-            {
-                if ( !dest.mkdir(currentName) )
-                    throw Exception(Exception::MkdirFail, dest.absoluteFilePath(currentName));
-                if ( !source.cd(currentName) )
-                    throw Exception(Exception::AccessDenied, source.absoluteFilePath(currentName));
-                if ( !dest.cd(currentName) )
-                    throw Exception(Exception::AccessDenied, dest.absoluteFilePath(currentName)); //quite impossible
-
-                stack.push(currentList);
-                currentList = source.entryInfoList( filters, QDir::DirsLast );
-            }
-            else
-            {
-                if ( !QFile::copy( source.absoluteFilePath(currentName), dest.absoluteFilePath(currentName) ) )
-                    throw Exception(Exception::CopyFail, source.absoluteFilePath(currentName));
-
-                if ( pd ) {
-                    bytesCopied += currentItem.size();
-                    pd->setValue(bytesCopied);
-                }
-            }
-        }
-        else // list is empty
-        {
-            if ( !stack.isEmpty() )
-            {
-                currentList = stack.pop();
-                source.cdUp();
-                dest.cdUp();
-            }
-            else
-                break;
-        }
-
-        if ( pd ) {
-            pd->processEvents();
-            if (pd->wasCanceled())
-                throw Exception(Exception::OperationCanceled);
-        }
-    }
-}
-
-void mergeDirs(const QString & sourcePath, const QString & destPath, ProgressDialogInterface *pd)
-{
-    QDir source(sourcePath);
-    if ( !source.exists() )
-        throw Exception(Exception::NoSuchFileOrDirectory, sourcePath);
-
-    QDir dest(destPath);
-    if ( !dest.exists() ) {
+    } else {
         dest.mkdir(dest.absolutePath());
     }
 
@@ -201,7 +122,6 @@ void mergeDirs(const QString & sourcePath, const QString & destPath, ProgressDia
         pd->setLabelText(QObject::tr("Copying files..."));
     }
 
-
     while(1)
     {
         if ( !currentList.isEmpty() )
@@ -211,12 +131,14 @@ void mergeDirs(const QString & sourcePath, const QString & destPath, ProgressDia
 
             if ( currentItem.isSymLink() )
             {
-                if ( QFile::exists(dest.absoluteFilePath(currentName)) )
-                   if(!QFile::remove(dest.absoluteFilePath(currentName)))
-                         throw Exception(Exception::RmFail,currentItem.absoluteFilePath());
+                if ( options & OverWrite ) {
+                    if ( QFile::exists(dest.absoluteFilePath(currentName)) &&
+                         !QFile::remove(dest.absoluteFilePath(currentName)) )
+                        throw Exception(Exception::RmFail, dest.absoluteFilePath(currentName));
+                }
                 if ( !QFile::link( relativeSymLinkTarget(source.absoluteFilePath(currentName)),
                                     dest.absoluteFilePath(currentName) ) )
-                    throw Exception(Exception::CopyFail, currentItem.absoluteFilePath());
+                    throw Exception(Exception::CopyFail, source.absoluteFilePath(currentName));
             }
             else if ( currentItem.isDir() )
             {
@@ -235,9 +157,11 @@ void mergeDirs(const QString & sourcePath, const QString & destPath, ProgressDia
             }
             else
             {
-                if ( QFile::exists( dest.absoluteFilePath(currentName)))
-                     if(!QFile::remove(dest.absoluteFilePath(currentName)))
+                if ( options & OverWrite ) {
+                    if ( QFile::exists(dest.absoluteFilePath(currentName)) &&
+                         !QFile::remove(dest.absoluteFilePath(currentName)) )
                         throw Exception(Exception::RmFail, dest.absoluteFilePath(currentName));
+                }
                 if ( !QFile::copy( source.absoluteFilePath(currentName), dest.absoluteFilePath(currentName) ) )
                     throw Exception(Exception::CopyFail, source.absoluteFilePath(currentName));
 
diff --git a/diroperations/diroperations.h b/diroperations/diroperations.h
index 4cdf67e..9726523 100644
--- a/diroperations/diroperations.h
+++ b/diroperations/diroperations.h
@@ -51,6 +51,10 @@ namespace DirOperations {
         QString m_info;
     };
 
+    enum CopyOption { NoOptions = 0x0, RemoveDestination = 0x1, OverWrite = 0x2 };
+    Q_DECLARE_FLAGS(CopyOptions, CopyOption);
+    Q_DECLARE_OPERATORS_FOR_FLAGS(CopyOptions);
+
     /*! Returns the target path of the symbolic link \a fileName .
      * The path returned is relative to the symlink. For example if
      * we have the following link:
@@ -65,17 +69,14 @@ namespace DirOperations {
 
     /*! Copies directory \a sourcePath and all of its contents
      * to directory \a destPath . Works like "cp -r".
+     * \a options can be the following:
+     * \li NoOptions - Nothing special happens
+     * \li RemoveDestination - It removes the destination directory before trying to copy.
+     * \li OverWrite - If a file exists both in \a sourcePath and in \a destPath, the the file will be overwritten.
      */
     void recursiveCpDir(const QString & sourcePath, const QString & destPath,
-                        bool force = false, ProgressDialogInterface *pd = 0);
+                        CopyOptions options = NoOptions, ProgressDialogInterface *pd = 0);
 
-    /*! Merges two directories, meaning that if a file exists in \a sourcePath and 
-     *  in \a destPath, then the the file will be overwritten, if a file only exists 
-     *  in destPath, it will stay and if it only exists in sourcePath, it will be ~
-     *  copied over 
-     */
-    void mergeDirs(const QString & sourcePath, const QString & destPath,
-			ProgressDialogInterface *pd = 0);
     /*! Deletes directory \a dir and all of its contents. Works like "rm -r". */
     void recursiveRmDir(const QString & dir, ProgressDialogInterface *pd = 0);
 
diff --git a/diroperations/unit_test/test.cpp b/diroperations/unit_test/test.cpp
index 8949d7c..6bdf2a5 100644
--- a/diroperations/unit_test/test.cpp
+++ b/diroperations/unit_test/test.cpp
@@ -43,7 +43,7 @@ Test::Test()
 void Test::docopy()
 {
     try {
-        DirOperations::mergeDirs(m_source->text(), m_dest->text(), m_progressWidget);
+        DirOperations::recursiveCpDir(m_source->text(), m_dest->text(), DirOperations::OverWrite, m_progressWidget);
     } catch (const DirOperations::Exception & e) {
         qDebug() << e.what();
         std::exit(1);
diff --git a/migrationpage.cpp b/migrationpage.cpp
index 7672516..e541e85 100644
--- a/migrationpage.cpp
+++ b/migrationpage.cpp
@@ -41,7 +41,8 @@ void MigrationPagePrivate::doMagic()
     {
       try
       {
-        DirOperations::recursiveCpDir(QDir::homePath()+KDEDIR,QDir::homePath()+KDE3BACKUPDIR,true,progress);
+        DirOperations::recursiveCpDir(QDir::homePath()+KDEDIR,QDir::homePath()+KDE3BACKUPDIR,
+                                       DirOperations::RemoveDestination,progress);
       }
       catch (DirOperations::Exception e)
       {
@@ -59,8 +60,8 @@ void MigrationPagePrivate::doMagic()
       qDebug() << "do nothing, let kconf_update do magic";
       break;
     case MigrationTool::Merge:
-      DirOperations::mergeDirs(QDir::homePath()+KDE4DIR,
-			         QDir::homePath()+KDEDIR,progress);
+      DirOperations::recursiveCpDir(QDir::homePath()+KDE4DIR,QDir::homePath()+KDEDIR,
+                                     DirOperations::OverWrite,progress);
       qDebug() << "do magic experimental merge";
       break;
     case MigrationTool::Clean:
@@ -68,7 +69,8 @@ void MigrationPagePrivate::doMagic()
       DirOperations::recursiveRmDir(QDir::homePath()+KDEDIR,progress);
       break;
     case MigrationTool::Move:
-      DirOperations::recursiveCpDir(QDir::homePath()+KDE4DIR,QDir::homePath()+KDEDIR,true /*force*/, progress);
+      DirOperations::recursiveCpDir(QDir::homePath()+KDE4DIR,QDir::homePath()+KDEDIR,
+                                     DirOperations::RemoveDestination, progress);
       qDebug() << "move .kde4 over .kde";
       break;
   }

-- 
Kaboom - Debian KDE 3->4 migration tool



More information about the pkg-kde-commits mailing list