| 497 | } |
| 498 | |
| 499 | static QStringList |
| 500 | findBackups(const QString & filePath) |
| 501 | { |
| 502 | QStringList ret; |
| 503 | if ( QFile::exists(filePath) ) { |
| 504 | ret.append(filePath); |
| 505 | } |
| 506 | // find files matching filePath.~[0-9]+~ |
| 507 | QRegExp rx(QString::fromUtf8("\\.~(\\d+)~$")); |
| 508 | QFileInfo fileInfo(filePath); |
| 509 | QString fileName = fileInfo.fileName(); |
| 510 | QDirIterator it(fileInfo.dir()); |
| 511 | while (it.hasNext()) { |
| 512 | QString filename = it.next(); |
| 513 | QFileInfo file(filename); |
| 514 | |
| 515 | if (file.isDir()) { // Check if it's a dir |
| 516 | continue; |
| 517 | } |
| 518 | |
| 519 | // If the filename contains target string - put it in the hitlist |
| 520 | QString fn = file.fileName(); |
| 521 | if (fn.startsWith(fileName) && rx.lastIndexIn(fn) == fileName.size()) { |
| 522 | ret.append(file.filePath()); |
| 523 | } |
| 524 | } |
| 525 | ret.sort(); |
| 526 | |
| 527 | return ret; |
| 528 | } |
| 529 | |
| 530 | // if filePath matches .*\.~[0-9]+~, increment the backup number |
| 531 | // else append .~1~ |
no test coverage detected