{"action":"created","comment":{"url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/comments/43230669","id":43230669,"diff_hunk":"@@ -112,57 +113,51 @@ QString Utils::Fs::folderName(const QString& file_path)\n }\n \n /**\n- * Remove an empty folder tree.\n- *\n- * This function will also remove .DS_Store files on Mac OS and\n- * Thumbs.db on Windows.\n+ * This function will first remove system cache files, e.g. `Thumbs.db`,\n+ * `.DS_Store`. Then will try to remove the whole tree if the tree consist\n+ * only of folders\n  */\n-bool Utils::Fs::smartRemoveEmptyFolderTree(const QString& dir_path)\n+bool Utils::Fs::smartRemoveEmptyFolderTree(const QString& path)\n {\n-    qDebug() << Q_FUNC_INFO << dir_path;\n-    if (dir_path.isEmpty())\n+    if (!QDir(path).exists())\n         return false;\n \n-    QDir dir(dir_path);\n-    if (!dir.exists())\n-        return true;\n-\n-    // Remove Files created by the OS\n-#if defined Q_OS_MAC\n-    forceRemove(dir_path + QLatin1String(\"/.DS_Store\"));\n-#elif defined Q_OS_WIN\n-    forceRemove(dir_path + QLatin1String(\"/Thumbs.db\"));\n+    static const QStringList deleteList = {\n+#if defined Q_OS_WIN\n+    \"Thumbs.db\", \"desktop.ini\"\n+#elif defined Q_OS_MAC\n+    \".DS_Store\"\n #endif\n-\n-    QFileInfoList sub_files = dir.entryInfoList();\n-    foreach (const QFileInfo& info, sub_files) {\n-        QString sub_name = info.fileName();\n-        if (sub_name == \".\" || sub_name == \"..\")\n-            continue;\n-\n-        QString sub_path = info.absoluteFilePath();\n-        qDebug() << Q_FUNC_INFO << \"sub file: \" << sub_path;\n-        if (info.isDir()) {\n-            if (!smartRemoveEmptyFolderTree(sub_path)) {\n-                qWarning() << Q_FUNC_INFO << \"Failed to remove folder: \" << sub_path;\n-                return false;\n-            }\n+    };\n+\n+    // travel from the deepest folder and remove anything unwanted on the way out.\n+    QStringList dirList(path + \"/\");  // get all sub directories paths\n+    QDirIterator iter(path, (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories);\n+    while (iter.hasNext())\n+        dirList << iter.next() + \"/\";\n+    std::sort(dirList.begin(), dirList.end(), [](const QString &l, const QString &r){return (l.count(\"/\") > r.count(\"/\"));});  // sort descending by directory depth\n+\n+    for(const QString &p : dirList) {","path":"src/core/utils/fs.cpp","position":66,"original_position":66,"commit_id":"db3b64e3e36d163ae413c16a2e4c16361f549ca2","original_commit_id":"db3b64e3e36d163ae413c16a2e4c16361f549ca2","user":{"login":"Chocobo1","id":9395168,"avatar_url":"https://avatars.githubusercontent.com/u/9395168?v=3","gravatar_id":"","url":"https://api.github.com/users/Chocobo1","html_url":"https://github.com/Chocobo1","followers_url":"https://api.github.com/users/Chocobo1/followers","following_url":"https://api.github.com/users/Chocobo1/following{/other_user}","gists_url":"https://api.github.com/users/Chocobo1/gists{/gist_id}","starred_url":"https://api.github.com/users/Chocobo1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chocobo1/subscriptions","organizations_url":"https://api.github.com/users/Chocobo1/orgs","repos_url":"https://api.github.com/users/Chocobo1/repos","events_url":"https://api.github.com/users/Chocobo1/events{/privacy}","received_events_url":"https://api.github.com/users/Chocobo1/received_events","type":"User","site_admin":false},"body":"Found a old blog post:\r\nhttps://blog.qt.io/blog/2009/01/23/iterating-efficiently/\r\n","created_at":"2015-10-28T09:06:04Z","updated_at":"2015-10-28T09:06:04Z","html_url":"https://github.com/qbittorrent/qBittorrent/pull/3604#discussion_r43230669","pull_request_url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604","_links":{"self":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/comments/43230669"},"html":{"href":"https://github.com/qbittorrent/qBittorrent/pull/3604#discussion_r43230669"},"pull_request":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604"}}},"pull_request":{"url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604","id":41967168,"html_url":"https://github.com/qbittorrent/qBittorrent/pull/3604","diff_url":"https://github.com/qbittorrent/qBittorrent/pull/3604.diff","patch_url":"https://github.com/qbittorrent/qBittorrent/pull/3604.patch","issue_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/3604","number":3604,"state":"open","locked":false,"title":"Don't remove torrent contents parent folder, even it is empty.","user":{"login":"Chocobo1","id":9395168,"avatar_url":"https://avatars.githubusercontent.com/u/9395168?v=3","gravatar_id":"","url":"https://api.github.com/users/Chocobo1","html_url":"https://github.com/Chocobo1","followers_url":"https://api.github.com/users/Chocobo1/followers","following_url":"https://api.github.com/users/Chocobo1/following{/other_user}","gists_url":"https://api.github.com/users/Chocobo1/gists{/gist_id}","starred_url":"https://api.github.com/users/Chocobo1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chocobo1/subscriptions","organizations_url":"https://api.github.com/users/Chocobo1/orgs","repos_url":"https://api.github.com/users/Chocobo1/repos","events_url":"https://api.github.com/users/Chocobo1/events{/privacy}","received_events_url":"https://api.github.com/users/Chocobo1/received_events","type":"User","site_admin":false},"body":"IMO, it makes no sense to delete torrent contents **parent** folder, no matter it is created by user or qbt.\r\nJust deleting the folder containing the contents is enough.\r\n\r\n#3144,  #3619 is probably related.\r\n\r\nShould I remove `Utils::Fs::smartRemoveEmptyFolderTree()`? It's not being called anymore after this PR.","created_at":"2015-08-09T08:18:05Z","updated_at":"2015-10-28T09:06:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8eee31c2041b3ac7b3234bc94289b3a2e6d1f30","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604/commits","review_comments_url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604/comments","review_comment_url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/3604/comments","statuses_url":"https://api.github.com/repos/qbittorrent/qBittorrent/statuses/db3b64e3e36d163ae413c16a2e4c16361f549ca2","head":{"label":"Chocobo1:deletion","ref":"deletion","sha":"db3b64e3e36d163ae413c16a2e4c16361f549ca2","user":{"login":"Chocobo1","id":9395168,"avatar_url":"https://avatars.githubusercontent.com/u/9395168?v=3","gravatar_id":"","url":"https://api.github.com/users/Chocobo1","html_url":"https://github.com/Chocobo1","followers_url":"https://api.github.com/users/Chocobo1/followers","following_url":"https://api.github.com/users/Chocobo1/following{/other_user}","gists_url":"https://api.github.com/users/Chocobo1/gists{/gist_id}","starred_url":"https://api.github.com/users/Chocobo1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chocobo1/subscriptions","organizations_url":"https://api.github.com/users/Chocobo1/orgs","repos_url":"https://api.github.com/users/Chocobo1/repos","events_url":"https://api.github.com/users/Chocobo1/events{/privacy}","received_events_url":"https://api.github.com/users/Chocobo1/received_events","type":"User","site_admin":false},"repo":{"id":30459428,"name":"qBittorrent","full_name":"Chocobo1/qBittorrent","owner":{"login":"Chocobo1","id":9395168,"avatar_url":"https://avatars.githubusercontent.com/u/9395168?v=3","gravatar_id":"","url":"https://api.github.com/users/Chocobo1","html_url":"https://github.com/Chocobo1","followers_url":"https://api.github.com/users/Chocobo1/followers","following_url":"https://api.github.com/users/Chocobo1/following{/other_user}","gists_url":"https://api.github.com/users/Chocobo1/gists{/gist_id}","starred_url":"https://api.github.com/users/Chocobo1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chocobo1/subscriptions","organizations_url":"https://api.github.com/users/Chocobo1/orgs","repos_url":"https://api.github.com/users/Chocobo1/repos","events_url":"https://api.github.com/users/Chocobo1/events{/privacy}","received_events_url":"https://api.github.com/users/Chocobo1/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Chocobo1/qBittorrent","description":"qBittorrent BitTorrent client","fork":true,"url":"https://api.github.com/repos/Chocobo1/qBittorrent","forks_url":"https://api.github.com/repos/Chocobo1/qBittorrent/forks","keys_url":"https://api.github.com/repos/Chocobo1/qBittorrent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Chocobo1/qBittorrent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Chocobo1/qBittorrent/teams","hooks_url":"https://api.github.com/repos/Chocobo1/qBittorrent/hooks","issue_events_url":"https://api.github.com/repos/Chocobo1/qBittorrent/issues/events{/number}","events_url":"https://api.github.com/repos/Chocobo1/qBittorrent/events","assignees_url":"https://api.github.com/repos/Chocobo1/qBittorrent/assignees{/user}","branches_url":"https://api.github.com/repos/Chocobo1/qBittorrent/branches{/branch}","tags_url":"https://api.github.com/repos/Chocobo1/qBittorrent/tags","blobs_url":"https://api.github.com/repos/Chocobo1/qBittorrent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Chocobo1/qBittorrent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Chocobo1/qBittorrent/git/refs{/sha}","trees_url":"https://api.github.com/repos/Chocobo1/qBittorrent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Chocobo1/qBittorrent/statuses/{sha}","languages_url":"https://api.github.com/repos/Chocobo1/qBittorrent/languages","stargazers_url":"https://api.github.com/repos/Chocobo1/qBittorrent/stargazers","contributors_url":"https://api.github.com/repos/Chocobo1/qBittorrent/contributors","subscribers_url":"https://api.github.com/repos/Chocobo1/qBittorrent/subscribers","subscription_url":"https://api.github.com/repos/Chocobo1/qBittorrent/subscription","commits_url":"https://api.github.com/repos/Chocobo1/qBittorrent/commits{/sha}","git_commits_url":"https://api.github.com/repos/Chocobo1/qBittorrent/git/commits{/sha}","comments_url":"https://api.github.com/repos/Chocobo1/qBittorrent/comments{/number}","issue_comment_url":"https://api.github.com/repos/Chocobo1/qBittorrent/issues/comments{/number}","contents_url":"https://api.github.com/repos/Chocobo1/qBittorrent/contents/{+path}","compare_url":"https://api.github.com/repos/Chocobo1/qBittorrent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Chocobo1/qBittorrent/merges","archive_url":"https://api.github.com/repos/Chocobo1/qBittorrent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Chocobo1/qBittorrent/downloads","issues_url":"https://api.github.com/repos/Chocobo1/qBittorrent/issues{/number}","pulls_url":"https://api.github.com/repos/Chocobo1/qBittorrent/pulls{/number}","milestones_url":"https://api.github.com/repos/Chocobo1/qBittorrent/milestones{/number}","notifications_url":"https://api.github.com/repos/Chocobo1/qBittorrent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Chocobo1/qBittorrent/labels{/name}","releases_url":"https://api.github.com/repos/Chocobo1/qBittorrent/releases{/id}","created_at":"2015-02-07T15:14:20Z","updated_at":"2015-06-14T11:04:06Z","pushed_at":"2015-10-28T08:06:09Z","git_url":"git://github.com/Chocobo1/qBittorrent.git","ssh_url":"git@github.com:Chocobo1/qBittorrent.git","clone_url":"https://github.com/Chocobo1/qBittorrent.git","svn_url":"https://github.com/Chocobo1/qBittorrent","homepage":"http://www.qbittorrent.org","size":112868,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"qbittorrent:master","ref":"master","sha":"c75725e2d8c8fd3f9248e1d7b9038c988a13ec68","user":{"login":"qbittorrent","id":2131270,"avatar_url":"https://avatars.githubusercontent.com/u/2131270?v=3","gravatar_id":"","url":"https://api.github.com/users/qbittorrent","html_url":"https://github.com/qbittorrent","followers_url":"https://api.github.com/users/qbittorrent/followers","following_url":"https://api.github.com/users/qbittorrent/following{/other_user}","gists_url":"https://api.github.com/users/qbittorrent/gists{/gist_id}","starred_url":"https://api.github.com/users/qbittorrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qbittorrent/subscriptions","organizations_url":"https://api.github.com/users/qbittorrent/orgs","repos_url":"https://api.github.com/users/qbittorrent/repos","events_url":"https://api.github.com/users/qbittorrent/events{/privacy}","received_events_url":"https://api.github.com/users/qbittorrent/received_events","type":"Organization","site_admin":false},"repo":{"id":3351871,"name":"qBittorrent","full_name":"qbittorrent/qBittorrent","owner":{"login":"qbittorrent","id":2131270,"avatar_url":"https://avatars.githubusercontent.com/u/2131270?v=3","gravatar_id":"","url":"https://api.github.com/users/qbittorrent","html_url":"https://github.com/qbittorrent","followers_url":"https://api.github.com/users/qbittorrent/followers","following_url":"https://api.github.com/users/qbittorrent/following{/other_user}","gists_url":"https://api.github.com/users/qbittorrent/gists{/gist_id}","starred_url":"https://api.github.com/users/qbittorrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qbittorrent/subscriptions","organizations_url":"https://api.github.com/users/qbittorrent/orgs","repos_url":"https://api.github.com/users/qbittorrent/repos","events_url":"https://api.github.com/users/qbittorrent/events{/privacy}","received_events_url":"https://api.github.com/users/qbittorrent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/qbittorrent/qBittorrent","description":"qBittorrent BitTorrent client","fork":false,"url":"https://api.github.com/repos/qbittorrent/qBittorrent","forks_url":"https://api.github.com/repos/qbittorrent/qBittorrent/forks","keys_url":"https://api.github.com/repos/qbittorrent/qBittorrent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qbittorrent/qBittorrent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qbittorrent/qBittorrent/teams","hooks_url":"https://api.github.com/repos/qbittorrent/qBittorrent/hooks","issue_events_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/events{/number}","events_url":"https://api.github.com/repos/qbittorrent/qBittorrent/events","assignees_url":"https://api.github.com/repos/qbittorrent/qBittorrent/assignees{/user}","branches_url":"https://api.github.com/repos/qbittorrent/qBittorrent/branches{/branch}","tags_url":"https://api.github.com/repos/qbittorrent/qBittorrent/tags","blobs_url":"https://api.github.com/repos/qbittorrent/qBittorrent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qbittorrent/qBittorrent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qbittorrent/qBittorrent/git/refs{/sha}","trees_url":"https://api.github.com/repos/qbittorrent/qBittorrent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qbittorrent/qBittorrent/statuses/{sha}","languages_url":"https://api.github.com/repos/qbittorrent/qBittorrent/languages","stargazers_url":"https://api.github.com/repos/qbittorrent/qBittorrent/stargazers","contributors_url":"https://api.github.com/repos/qbittorrent/qBittorrent/contributors","subscribers_url":"https://api.github.com/repos/qbittorrent/qBittorrent/subscribers","subscription_url":"https://api.github.com/repos/qbittorrent/qBittorrent/subscription","commits_url":"https://api.github.com/repos/qbittorrent/qBittorrent/commits{/sha}","git_commits_url":"https://api.github.com/repos/qbittorrent/qBittorrent/git/commits{/sha}","comments_url":"https://api.github.com/repos/qbittorrent/qBittorrent/comments{/number}","issue_comment_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/comments{/number}","contents_url":"https://api.github.com/repos/qbittorrent/qBittorrent/contents/{+path}","compare_url":"https://api.github.com/repos/qbittorrent/qBittorrent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qbittorrent/qBittorrent/merges","archive_url":"https://api.github.com/repos/qbittorrent/qBittorrent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qbittorrent/qBittorrent/downloads","issues_url":"https://api.github.com/repos/qbittorrent/qBittorrent/issues{/number}","pulls_url":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls{/number}","milestones_url":"https://api.github.com/repos/qbittorrent/qBittorrent/milestones{/number}","notifications_url":"https://api.github.com/repos/qbittorrent/qBittorrent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qbittorrent/qBittorrent/labels{/name}","releases_url":"https://api.github.com/repos/qbittorrent/qBittorrent/releases{/id}","created_at":"2012-02-04T09:37:46Z","updated_at":"2015-10-28T01:22:03Z","pushed_at":"2015-10-28T08:11:44Z","git_url":"git://github.com/qbittorrent/qBittorrent.git","ssh_url":"git@github.com:qbittorrent/qBittorrent.git","clone_url":"https://github.com/qbittorrent/qBittorrent.git","svn_url":"https://github.com/qbittorrent/qBittorrent","homepage":"http://www.qbittorrent.org","size":129854,"stargazers_count":1266,"watchers_count":1266,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":365,"mirror_url":null,"open_issues_count":1166,"forks":365,"open_issues":1166,"watchers":1266,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604"},"html":{"href":"https://github.com/qbittorrent/qBittorrent/pull/3604"},"issue":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/3604"},"comments":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/issues/3604/comments"},"review_comments":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604/comments"},"review_comment":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/pulls/3604/commits"},"statuses":{"href":"https://api.github.com/repos/qbittorrent/qBittorrent/statuses/db3b64e3e36d163ae413c16a2e4c16361f549ca2"}}}}