]> Some of my projects - localmylist.git/commitdiff
Add setting to control removal of directories during rename.
authorAPTX <marek321@gmail.com>
Fri, 26 Apr 2013 20:02:53 +0000 (22:02 +0200)
committerAPTX <marek321@gmail.com>
Fri, 26 Apr 2013 20:02:53 +0000 (22:02 +0200)
localmylist/renamehandler.cpp
localmylist/share/schema/default_config.sql

index 75fc24a2ab68422bb0ed54b891beb01b9eab054b..52c160c664c4cec2bf37d5f49d2c4d3717e13ba3 100644 (file)
@@ -182,26 +182,29 @@ void RenameHandler::handleRename()
 
                db->log(tr("Rename: File <%1> was renamed to <%2>").arg(oldFile.canonicalFilePath()).arg(newFileString));
 
-               QDir dir = oldFile.dir();
-               dir.setFilter(QDir::NoDotAndDotDot | QDir::AllEntries);
-               while (!dir.count())
+               if (settings->get("renameRemoveEmptyDirectories", false))
                {
-                       for (const QString &path : watchedDirectories)
+                       QDir dir = oldFile.dir();
+                       dir.setFilter(QDir::NoDotAndDotDot | QDir::AllEntries);
+                       while (!dir.count())
                        {
-                               QDir watchedDirectory(path);
-                               if (dir.canonicalPath() == watchedDirectory.canonicalPath())
-                                       goto endDirRemove;
+                               for (const QString &path : watchedDirectories)
+                               {
+                                       QDir watchedDirectory(path);
+                                       if (dir.canonicalPath() == watchedDirectory.canonicalPath())
+                                               goto endDirRemove;
+                               }
+                               // QDir::rmdir only removes empty directories
+                               if (!dir.rmdir(dir.canonicalPath()))
+                               {
+                                       qDebug() << "Failed to remove directory " << dir.path();
+                                       break;
+                               }
+                               if (!dir.cdUp())
+                                       break;
                        }
-                       // QDir::rmdir only removes empty directories
-                       if (!dir.rmdir(dir.canonicalPath()))
-                       {
-                               qDebug() << "Failed to remove directory " << dir.path();
-                               break;
-                       }
-                       if (!dir.cdUp())
-                               break;
-               }
 endDirRemove: ;
+               }
        }
 
        emit renameBatchFinished();
index 3997932dcfe33ca4fe6706ea8b38ec4c7dd7a0fd..6ad9cdb8f8a5f96825706e587972cb464324d813 100644 (file)
@@ -22,6 +22,7 @@ INSERT INTO config VALUES ('myListDefaultSource', NULL, true);
 INSERT INTO config VALUES ('renameScript', NULL, true);
 INSERT INTO config VALUES ('renameLanguage', NULL, true);
 INSERT INTO config VALUES ('renameSanitizeRegex', '[/\:*"?<>|\r\n]', true); -- This assumes \ does not need escaping, which is what current pg does by default.
+INSERT INTO config VALUES ('renameRemoveEmptyDirectories', '1', true);
 INSERT INTO config VALUES ('enableRename', '0', true);
 
 INSERT INTO config VALUES ('fileFilters', '*.mkv *.mp4 *.ogg *.ogm *.wmv *.avi *.mpg *.flv', true);