Add namespace and prepare unittest

This commit is contained in:
Alexis Lopez Zubieta
2018-11-04 14:59:27 -06:00
parent 7318d68c96
commit 1fa90fbd5c
5 changed files with 156 additions and 59 deletions
+55 -54
View File
@@ -13,68 +13,69 @@ using namespace linuxdeploy::core::log;
using namespace linuxdeploy::util;
namespace bf = boost::filesystem;
namespace linuxdeploy {
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
args::ValueFlag<std::string>& customAppRunPath, appdir::AppDir& appDir) {
// search for desktop file and deploy it to AppDir root
ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl;
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
args::ValueFlag<std::string>& customAppRunPath, appdir::AppDir& appDir) {
// search for desktop file and deploy it to AppDir root
ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl;
if (is_regular_file(appDir.path() / "AppRun")) {
if (customAppRunPath)
ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun"
<< std::endl;
else
ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl;
} else {
auto deployedDesktopFiles = appDir.deployedDesktopFiles();
desktopfile::DesktopFile desktopFile;
if (deployedDesktopFiles.empty()) {
ldLog() << LD_WARNING
<< "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root"
<< std::endl;
if (is_regular_file(appDir.path() / "AppRun")) {
if (customAppRunPath)
ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun"
<< std::endl;
else
ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl;
} else {
if (!desktopFilePaths.Get().empty()) {
auto firstDeployedDesktopFileName = boost::filesystem::path(
desktopFilePaths.Get().front()).filename().string();
auto deployedDesktopFiles = appDir.deployedDesktopFiles();
auto desktopFileMatchingName = find_if(
deployedDesktopFiles.begin(),
deployedDesktopFiles.end(),
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
auto fileName = desktopFile.path().filename().string();
return fileName == firstDeployedDesktopFileName;
desktopfile::DesktopFile desktopFile;
if (deployedDesktopFiles.empty()) {
ldLog() << LD_WARNING
<< "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root"
<< std::endl;
} else {
if (!desktopFilePaths.Get().empty()) {
auto firstDeployedDesktopFileName = boost::filesystem::path(
desktopFilePaths.Get().front()).filename().string();
auto desktopFileMatchingName = find_if(
deployedDesktopFiles.begin(),
deployedDesktopFiles.end(),
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
auto fileName = desktopFile.path().filename().string();
return fileName == firstDeployedDesktopFileName;
}
);
if (desktopFileMatchingName != deployedDesktopFiles.end()) {
desktopFile = *desktopFileMatchingName;
} else {
ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:"
<< firstDeployedDesktopFileName << std::endl;
return 1;
}
);
if (desktopFileMatchingName != deployedDesktopFiles.end()) {
desktopFile = *desktopFileMatchingName;
} else {
ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:"
<< firstDeployedDesktopFileName << std::endl;
desktopFile = deployedDesktopFiles[0];
ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:"
<< desktopFile.path() << std::endl;
}
ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl;
bool rv;
if (customAppRunPath) {
rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get());
} else {
rv = appDir.createLinksInAppDirRoot(desktopFile);
}
if (!rv) {
return 1;
}
} else {
desktopFile = deployedDesktopFiles[0];
ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:"
<< desktopFile.path() << std::endl;
}
ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl;
bool rv;
if (customAppRunPath) {
rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get());
} else {
rv = appDir.createLinksInAppDirRoot(desktopFile);
}
if (!rv) {
return 1;
}
}
return true;
}
return true;
}