ours
| 274 | |
| 275 | // ours |
| 276 | std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target) |
| 277 | { |
| 278 | QDir directory(target); |
| 279 | QStringList extracted; |
| 280 | |
| 281 | qDebug() << "Extracting subdir" << subdir << "from" << zip->getZipName() << "to" << target; |
| 282 | auto numEntries = zip->getEntriesCount(); |
| 283 | if(numEntries < 0) { |
| 284 | qWarning() << "Failed to enumerate files in archive"; |
| 285 | return std::nullopt; |
| 286 | } |
| 287 | else if(numEntries == 0) { |
| 288 | qDebug() << "Extracting empty archives seems odd..."; |
| 289 | return extracted; |
| 290 | } |
| 291 | else if (!zip->goToFirstFile()) |
| 292 | { |
| 293 | qWarning() << "Failed to seek to first file in zip"; |
| 294 | return std::nullopt; |
| 295 | } |
| 296 | |
| 297 | do |
| 298 | { |
| 299 | QString name = zip->getCurrentFileName(); |
| 300 | if(!QDir::cleanPath(name).startsWith(subdir)) |
| 301 | { |
| 302 | continue; |
| 303 | } |
| 304 | if (QDir::isAbsolutePath(name) || QDir::cleanPath(name).startsWith("..")) |
| 305 | { |
| 306 | qDebug() << "extractSubDir: Skipping file that tries to place itself in an absolute location or in a parent directory."; |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | name.remove(0, subdir.size()); |
| 311 | auto original_name = name; |
| 312 | |
| 313 | // Fix weird "folders with a single file get squashed" thing |
| 314 | QString path; |
| 315 | if(name.contains('/') && !name.endsWith('/')){ |
| 316 | path = name.section('/', 0, -2) + "/"; |
| 317 | FS::ensureFolderPathExists(FS::PathCombine(target, path)); |
| 318 | |
| 319 | name = name.split('/').last(); |
| 320 | } |
| 321 | |
| 322 | QString absFilePath; |
| 323 | if(name.isEmpty()) |
| 324 | { |
| 325 | absFilePath = directory.absoluteFilePath(name) + "/"; |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | absFilePath = directory.absoluteFilePath(path + name); |
| 330 | } |
| 331 | |
| 332 | if (!JlCompress::extractFile(zip, "", absFilePath)) |
| 333 | { |
nothing calls this directly
no test coverage detected