| 11 | namespace cli { |
| 12 | namespace commands { |
| 13 | void IntegrateCommand::exec(QList<QString> arguments) { |
| 14 | if (arguments.empty()) { |
| 15 | throw InvalidArgumentsError("No AppImages passed on commandline"); |
| 16 | } |
| 17 | |
| 18 | // make sure all AppImages exist on disk before further processing |
| 19 | for (auto& path : arguments) { |
| 20 | if (!QFileInfo(path).exists()) { |
| 21 | throw UsageError("could not find file " + path); |
| 22 | } |
| 23 | |
| 24 | // make path absolute |
| 25 | // that will just prevent mistakes in libappimage and shared etc. |
| 26 | // (stuff like TryExec keys etc. being set to paths relative to CWD when running the command , ...) |
| 27 | path = QFileInfo(path).absoluteFilePath(); |
| 28 | } |
| 29 | |
| 30 | for (const auto& pathToAppImage : arguments) { |
| 31 | qout() << "Processing " << pathToAppImage << endl; |
| 32 | |
| 33 | if (!QFileInfo(pathToAppImage).isFile()) { |
| 34 | qerr() << "Warning: Not a file, skipping: " << pathToAppImage << endl; |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | if (!isAppImage(pathToAppImage)) { |
| 39 | qerr() << "Warning: Not an AppImage, skipping: " << pathToAppImage << endl; |
| 40 | continue; |
| 41 | } |
| 42 | |
| 43 | if (hasAlreadyBeenIntegrated(pathToAppImage)) { |
| 44 | if (desktopFileHasBeenUpdatedSinceLastUpdate(pathToAppImage)) { |
| 45 | qout() << "AppImage has been integrated already and doesn't need to be re-integrated, skipping" << endl; |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | qout() << "AppImage has already been integrated, but needs to be reintegrated" << endl; |
| 50 | } |
| 51 | |
| 52 | auto pathToIntegratedAppImage = buildPathToIntegratedAppImage(pathToAppImage); |
| 53 | |
| 54 | // make sure integration directory exists |
| 55 | // (important for new installations) |
| 56 | // pretty ugly, but well, one taketh what the Qt API giveth |
| 57 | QDir().mkdir(integratedAppImagesDestination().path()); |
| 58 | |
| 59 | // check if it's already in the right place |
| 60 | if (QFileInfo(pathToAppImage).absoluteFilePath() != QFileInfo(pathToIntegratedAppImage).absoluteFilePath()) { |
| 61 | qout() << "Moving AppImage to integration directory" << endl; |
| 62 | |
| 63 | if (QFile::exists(pathToIntegratedAppImage) && !QFile(pathToIntegratedAppImage).remove()) { |
| 64 | qerr() << "Could not move AppImage into integration directory (error: failed to overwrite existing file)" << endl; |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | if (!QFile(pathToAppImage).rename(pathToIntegratedAppImage)) { |
| 69 | qerr() << "Cannot move AppImage to integration directory (permission problem?), attempting to copy instead" << endl; |
| 70 |
no test coverage detected