Skip to content

Commit

Permalink
fix: get home path from /home/sleduc in first on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Leduc committed Oct 8, 2024
1 parent 0047018 commit 0162a0c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/CmdOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ std::string CmdOptions::getOptionString(const std::string & optionName)
CmdOptions::CmdOptions()
{
fs::detail::utf8_codecvt_facet utf8;
fs::path remakenRootPath = PathBuilder::getHomePath() / Constants::REMAKEN_FOLDER;
fs::path remakenRootPath = PathBuilder::getHomePath(*this) / Constants::REMAKEN_FOLDER;
remakenRootPath /= "packages";
char * rootDirectoryVar = getenv(Constants::REMAKENPKGROOT);
if (rootDirectoryVar != nullptr) {
Expand All @@ -144,7 +144,7 @@ CmdOptions::CmdOptions()
remakenRootPath = pkgPath;
}

fs::path remakenProfileFolder = PathBuilder::getHomePath() / Constants::REMAKEN_FOLDER / Constants::REMAKEN_PROFILES_FOLDER ;
fs::path remakenProfileFolder = PathBuilder::getHomePath(*this) / Constants::REMAKEN_FOLDER / Constants::REMAKEN_PROFILES_FOLDER ;
std::string profileName = "default";
m_cliApp.require_subcommand(1);
m_cliApp.fallthrough(true);
Expand Down Expand Up @@ -537,7 +537,7 @@ CmdOptions::OptionResult CmdOptions::parseArguments(int argc, char** argv)
void CmdOptions::writeConfigurationFile() const
{
fs::detail::utf8_codecvt_facet utf8;
fs::path remakenRootPath = PathBuilder::getHomePath() / Constants::REMAKEN_FOLDER;
fs::path remakenRootPath = PathBuilder::getHomePath(*this) / Constants::REMAKEN_FOLDER;
fs::path remakenProfilesPath = remakenRootPath / Constants::REMAKEN_PROFILES_FOLDER;
if (!fs::exists(remakenProfilesPath)) {
fs::create_directories(remakenProfilesPath);
Expand Down
10 changes: 5 additions & 5 deletions src/commands/InitCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int setupBrew()

int setupArtifactPackager(const CmdOptions & options)
{
fs::path remakenRootPath = PathBuilder::getHomePath() / Constants::REMAKEN_FOLDER;
fs::path remakenRootPath = PathBuilder::getHomePath(options) / Constants::REMAKEN_FOLDER;
fs::path remakenScriptsPath = remakenRootPath / "scripts";

if (!fs::exists(remakenScriptsPath)) {
Expand Down Expand Up @@ -99,13 +99,13 @@ int setupArtifactPackager(const CmdOptions & options)
return 0;
}

int setupWizards(const fs::path & rulesPath)
int setupWizards(const fs::path & rulesPath, const CmdOptions & options)
{
BOOST_LOG_TRIVIAL(info)<<"Installing qt creator wizards";
#ifdef BOOST_OS_WINDOWS_AVAILABLE
fs::path qtWizardsPath = PathBuilder::getUTF8PathObserver(getenv("APPDATA"));
#else
fs::path qtWizardsPath = PathBuilder::getHomePath()/".config";
fs::path qtWizardsPath = PathBuilder::getHomePath(options)/".config";
#endif
qtWizardsPath /= "QtProject";
qtWizardsPath /= "qtcreator";
Expand Down Expand Up @@ -150,7 +150,7 @@ int InitCommand::execute()
}

// process init command
fs::path remakenRootPath = PathBuilder::getHomePath() / Constants::REMAKEN_FOLDER;
fs::path remakenRootPath = PathBuilder::getHomePath(m_options) / Constants::REMAKEN_FOLDER;
fs::path remakenRulesPath = remakenRootPath / "rules";
fs::path remakenProfilesPath = remakenRootPath / Constants::REMAKEN_PROFILES_FOLDER;
fs::path qmakeRootPath = remakenRulesPath / "qmake";
Expand Down Expand Up @@ -188,7 +188,7 @@ int InitCommand::execute()
}

if (m_options.installWizards() || subCommand == "wizards") {
setupWizards(qmakeRootPath);
setupWizards(qmakeRootPath, m_options);
}
return 0;
}
28 changes: 18 additions & 10 deletions src/utils/PathBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
#include <boost/predef/os.h>
#include "Constants.h"
#include <boost/log/trivial.hpp>

#ifdef WIN32
#include <stdlib.h>
Expand Down Expand Up @@ -113,7 +114,7 @@ fs::path PathBuilder::buildModuleFilePath(const std::string & moduleName, const
return filePath;
}

fs::path PathBuilder::getHomePath()
fs::path PathBuilder::getHomePath(const CmdOptions & options)
{
char * homePathStr;
fs::path homePath;
Expand All @@ -129,23 +130,30 @@ fs::path PathBuilder::getHomePath()
else {
homePath = getUTF8PathObserver(homePathStr);
}
#else
struct passwd* pwd = getpwuid(getuid());
if (pwd) {
homePathStr = pwd->pw_dir;
#else \
// try first with the $HOME environment variable
homePathStr = getenv("HOME");
if (homePathStr == NULL)
{
struct passwd* pwd = getpwuid(getuid());
if (pwd) {
homePathStr = pwd->pw_dir;
if (options.getVerbose()) {
BOOST_LOG_TRIVIAL(info)<<"remaken getHomePath with getpwuid(getuid()) method "<<homePathStr;
}
}
}
else {
// try the $HOME environment variable
homePathStr = getenv("HOME");
if (options.getVerbose()) {
BOOST_LOG_TRIVIAL(info)<<"remaken getHomePath "<<homePathStr;
}
homePath = getUTF8PathObserver(homePathStr);
#endif
return homePath;
}

fs::path PathBuilder::getXPCFHomePath()
fs::path PathBuilder::getXPCFHomePath(const CmdOptions & options)
{
fs::path xpcfHomePath = getHomePath();
fs::path xpcfHomePath = getHomePath(options);
xpcfHomePath /= ".xpcf";
return xpcfHomePath;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/PathBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class PathBuilder
static fs::path replaceRootEnvVars(const std::string & sourcePath, const CmdOptions & options);
static fs::path buildModuleFilePath(const std::string & moduleName,const std::string & filePath, const CmdOptions & options);
static fs::path buildModuleFolderPath(const std::string & filePath, const CmdOptions & options);
static fs::path getHomePath();
static fs::path getXPCFHomePath();
static fs::path getHomePath(const CmdOptions & options);
static fs::path getXPCFHomePath(const CmdOptions & options);
static fs::path appendModuleDecorations(const fs::path & sl);
static fs::path appendModuleDecorations(const char * sl);
static inline bool is_shared_library(const std::string& s) {
Expand Down

0 comments on commit 0162a0c

Please sign in to comment.