| 172 | } |
| 173 | |
| 174 | bool deletePath(QString path) |
| 175 | { |
| 176 | bool OK = true; |
| 177 | QFileInfo finfo(path); |
| 178 | if(finfo.isFile()) { |
| 179 | return QFile::remove(path); |
| 180 | } |
| 181 | |
| 182 | QDir dir(path); |
| 183 | |
| 184 | if (!dir.exists()) |
| 185 | { |
| 186 | return OK; |
| 187 | } |
| 188 | auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | |
| 189 | QDir::AllDirs | QDir::Files, |
| 190 | QDir::DirsFirst); |
| 191 | |
| 192 | for(auto & info: allEntries) |
| 193 | { |
| 194 | #if defined Q_OS_WIN32 |
| 195 | QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath()); |
| 196 | auto wString = nativePath.toStdWString(); |
| 197 | DWORD dwAttrs = GetFileAttributesW(wString.c_str()); |
| 198 | // Windows: check for junctions, reparse points and other nasty things of that sort |
| 199 | if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT) |
| 200 | { |
| 201 | if (info.isFile()) |
| 202 | { |
| 203 | OK &= QFile::remove(info.absoluteFilePath()); |
| 204 | } |
| 205 | else if (info.isDir()) |
| 206 | { |
| 207 | OK &= dir.rmdir(info.absoluteFilePath()); |
| 208 | } |
| 209 | } |
| 210 | #else |
| 211 | // We do not trust Qt with reparse points, but do trust it with unix symlinks. |
| 212 | if(info.isSymLink()) |
| 213 | { |
| 214 | OK &= QFile::remove(info.absoluteFilePath()); |
| 215 | } |
| 216 | #endif |
| 217 | else if (info.isDir()) |
| 218 | { |
| 219 | OK &= deletePath(info.absoluteFilePath()); |
| 220 | } |
| 221 | else if (info.isFile()) |
| 222 | { |
| 223 | OK &= QFile::remove(info.absoluteFilePath()); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | OK = false; |
| 228 | qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath(); |
| 229 | } |
| 230 | } |
| 231 | OK &= dir.rmdir(dir.absolutePath()); |
no test coverage detected