Skip to content

Commit 2d73391

Browse files
committed
Windows-related fixes
* Fixed git path memory * Fixed recursive dir copy behavior
1 parent 41e3f9f commit 2d73391

11 files changed

Lines changed: 150 additions & 18 deletions

File tree

CMake.in.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SET(OFBUILD_CUSTOM_CMAKE_VERSION "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.
2323
SET(OPENFLUID_VERSION_MAJOR 2)
2424
SET(OPENFLUID_VERSION_MINOR 2)
2525
SET(OPENFLUID_VERSION_PATCH 0)
26-
SET(OPENFLUID_VERSION_STATUS "alpha100") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
26+
SET(OPENFLUID_VERSION_STATUS "alpha101") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
2727

2828
SET(OPENFLUID_VERSION_FULL "${OPENFLUID_VERSION_MAJOR}.${OPENFLUID_VERSION_MINOR}.${OPENFLUID_VERSION_PATCH}")
2929

cmake/OpenFLUIDConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ IF(NOT OpenFLUID_FOUND)
149149
OUTPUT_VARIABLE _OpenFLUID_CMD_OUTPUT
150150
)
151151

152+
IF(NOT DEFINED _OpenFLUID_CMD_OUTPUT)
153+
_OpenFLUID_RETURN("Unable to find version from OpenFLUID program")
154+
ENDIF()
155+
152156
STRING(FIND ${_OpenFLUID_CMD_OUTPUT} ${_OpenFLUID_VERSION} _OpenFLUID_CMD_TEST_VERSION)
153157

154158
IF(${_OpenFLUID_CMD_TEST_VERSION} LESS 0)

src/openfluid/tools/Filesystem.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@file Filesystem.cpp
3535
3636
@author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37+
@author Armel THÖNI <armel.thoni@inrae.fr>
3738
*/
3839

3940

@@ -282,6 +283,43 @@ bool Filesystem::copyDirectory(const std::string& SrcPath, const std::string& De
282283
// =====================================================================
283284

284285

286+
bool Filesystem::copyDirectoryContent(const std::filesystem::path& Source, const std::filesystem::path& Destination)
287+
{
288+
// was a filesystem::copy but not working when destination directory already exists under Windows,
289+
// even with copy_options::update_existing
290+
const auto CopyOptions = std::filesystem::copy_options::update_existing |
291+
std::filesystem::copy_options::recursive;
292+
for (const auto& E : std::filesystem::recursive_directory_iterator(Source))
293+
{
294+
const auto SourceItem = E.path();
295+
const auto DestinationItem = Destination / std::filesystem::relative(SourceItem, Source);
296+
297+
try
298+
{
299+
if (std::filesystem::is_directory(SourceItem))
300+
{
301+
std::filesystem::create_directories(DestinationItem);
302+
}
303+
else
304+
{
305+
std::filesystem::copy_file(SourceItem, DestinationItem, CopyOptions);
306+
}
307+
}
308+
catch (const std::filesystem::filesystem_error& e)
309+
{
310+
//TODO cleaner exception / logging management
311+
std::cerr << "Filesystem error: " << e.what() << std::endl;
312+
//return false; TOIMPL reenable this after test under windows
313+
}
314+
}
315+
return true;
316+
}
317+
318+
319+
// =====================================================================
320+
// =====================================================================
321+
322+
285323
bool Filesystem::emptyDirectory(const std::string& Path)
286324
{
287325
auto PathFSP = FilesystemPath(Path);

src/openfluid/tools/Filesystem.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ class OPENFLUID_API Filesystem
212212
static bool copyDirectory(const std::string& SrcPath, const std::string& DestPath,
213213
bool WithBaseDir = false, bool RemoveExisting = false);
214214

215+
216+
/**
217+
Recursively copies content of a directory from source to destination, handling windows bug with regular dir copy.
218+
@param[in] SrcPath the source path
219+
@param[in] DestPath the destination path
220+
@return true if the directory was successfully copied, false otherwise
221+
*/
222+
static bool copyDirectoryContent(const std::filesystem::path& SrcPath, const std::filesystem::path& DestPath);
223+
215224
/**
216225
Recursively removes all files and directories contained in the given directory.
217226
It deletes the directory and recreates it.

src/openfluid/tools/tests/Filesystem_TEST.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@file Filesystem_TEST.cpp
3535
3636
@author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37+
@author Armel THÖNI <armel.thoni@inrae.fr>
3738
*/
3839

3940

@@ -44,6 +45,7 @@
4445

4546

4647
#include <set>
48+
#include <fstream>
4749
#include <iostream>
4850
#include <filesystem>
4951

@@ -210,6 +212,24 @@ BOOST_AUTO_TEST_CASE(check_dirfiles_operations)
210212
BOOST_REQUIRE(openfluid::tools::FilesystemPath(WorkDir).isFile("DirCopyContent/subdir/another_subdir/README"));
211213
BOOST_REQUIRE(openfluid::tools::FilesystemPath(WorkDir).isDirectory("DirCopyContent/subdir/another_subdir"));
212214

215+
// merge dir content with existing
216+
217+
// emulate existing content
218+
std::filesystem::create_directory(WorkDir+"/ExistingDir");
219+
std::filesystem::create_directory(WorkDir+"/ExistingDir/subdir");
220+
std::ofstream(WorkDir+"/ExistingDir/EXISTING.txt").flush();
221+
std::ofstream(WorkDir+"/ExistingDir/subdir/SUBEXISTING.txt").flush();
222+
223+
// adding directory content
224+
BOOST_REQUIRE(openfluid::tools::Filesystem::copyDirectoryContent(FSInputPath,WorkDir+"/ExistingDir"));
225+
226+
// checking previous files
227+
BOOST_REQUIRE(openfluid::tools::FilesystemPath(WorkDir).isFile("ExistingDir/EXISTING.txt"));
228+
BOOST_REQUIRE(openfluid::tools::FilesystemPath(WorkDir).isFile("ExistingDir/subdir/SUBEXISTING.txt"));
229+
// checking copied files
230+
BOOST_REQUIRE(openfluid::tools::FilesystemPath(WorkDir).isFile("ExistingDir/README.TOO"));
231+
BOOST_REQUIRE(openfluid::tools::FilesystemPath(WorkDir).isFile("ExistingDir/subdir/another_subdir/README"));
232+
213233
}
214234

215235

src/openfluid/ui/waresdev/GitUIProxy.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ bool GitUIProxy::launchAuthCommand(QStringList Args, const QString& FromUrl, con
137137
{
138138
if (FromUrl.isEmpty() || ToPath.isEmpty())
139139
{
140+
// TODO for non GUI interface, find a way to redirect error/info
141+
//std::cout << "Empty remote url or empty destination path" << std::endl;
140142
emit error(tr("Empty remote url or empty destination path"));
141143
return false;
142144
}
@@ -149,6 +151,7 @@ bool GitUIProxy::launchAuthCommand(QStringList Args, const QString& FromUrl, con
149151
openfluid::tools::FilesystemPath({WorkingDirectory.toStdString(), ".git", "index.lock"});
150152
if (GitIndexLockPath.exists())
151153
{
154+
//std::cout << "Can not operate, git lock detected:" << std::endl;
152155
emit error(tr("Can not operate, git lock detected."));
153156
return false;
154157
}
@@ -199,13 +202,30 @@ bool GitUIProxy::launchAuthCommand(QStringList Args, const QString& FromUrl, con
199202
connect(mp_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(processStandardOutput()));
200203
connect(mp_Process, SIGNAL(readyReadStandardError()), this, SLOT(processErrorOutputAsInfo()));
201204

202-
mp_Process->start(QString::fromStdString(m_ExecutablePath),Args);
203-
205+
// TO BE USED IN INTERNAL LOGGING STACK AS "INFO"
206+
// std::cout << "PROCESS START:" << m_LocalGitProgram << " : ";
207+
// for (auto& p : Args)
208+
// {
209+
// std::cout << " " << p.toStdString() << std::endl;
210+
// }
211+
// std::cout << std::endl;
212+
mp_Process->start(QString::fromStdString(m_LocalGitProgram),Args);
213+
if (!mp_Process->waitForStarted())
214+
{
215+
delete mp_Process;
216+
mp_Process = nullptr;
217+
//std::cout << "failed start:" << std::endl; TODO add to logging
218+
return false;
219+
}
220+
// std::cout << "PROCESS POST START" << std::endl;
204221
mp_Process->waitForFinished(-1);
205222
mp_Process->waitForReadyRead(-1);
206223

207224
QString Res = QString::fromUtf8(mp_Process->readAll());
225+
226+
// std::cout << "PROCESS READ" << Res.toStdString() << std::endl;
208227
int ErrCode = mp_Process->exitCode();
228+
// !std::cout << "EXIT:" << ErrCode << std::endl;
209229

210230
delete mp_Process;
211231
mp_Process = nullptr;
@@ -298,11 +318,7 @@ std::pair<bool, QString> GitUIProxy::removeSubmodule(const QString& MainPathStr
298318
QProcess* Process = new QProcess();
299319
Process->setWorkingDirectory(MainPathString);
300320

301-
#if (QT_VERSION_MAJOR < 6)
302-
Process->start(QString::fromStdString(m_ExecutablePath),{"rm", "--cached", ".gitmodules"});
303-
#else
304-
Process->start(QString::fromStdString(m_ExecutablePath),{"rm", "--cached", ".gitmodules"});
305-
#endif
321+
Process->start(QString::fromStdString(m_LocalGitProgram),{"rm", "--cached", ".gitmodules"});
306322
Process->waitForReadyRead(-1);
307323
Process->waitForFinished(-1);
308324
int ErrCode = Process->exitCode();
@@ -326,6 +342,7 @@ std::pair<bool, QString> GitUIProxy::removeSubmodule(const QString& MainPathStr
326342
{
327343
StandardOutput += tr("Submodule successfully removed");
328344
}
345+
//TODO for logging system std::cout << "OUT IN REMOVE:" << StandardOutput.toStdString() << std::endl;
329346
return std::pair(SummaryStatusCode, StandardOutput);
330347
}
331348

@@ -470,11 +487,7 @@ std::pair<int, QString> GitUIProxy::launchLocalCommand(const QString& Path, QStr
470487
QProcess LocalProcess;
471488
LocalProcess.setWorkingDirectory(Path);
472489

473-
#if (QT_VERSION_MAJOR < 6)
474-
LocalProcess.start(QString::fromStdString(m_ExecutablePath),Args);
475-
#else
476-
LocalProcess.start(QString::fromStdString(m_ExecutablePath),Args);
477-
#endif
490+
LocalProcess.start(QString::fromStdString(m_LocalGitProgram),Args);
478491

479492
LocalProcess.waitForReadyRead(-1);
480493
LocalProcess.waitForFinished(-1);

src/openfluid/utils/CMakeProxy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ void CMakeProxy::findCMakeProgram()
6565
m_Version.erase(0,14);
6666
}
6767
}
68+
else
69+
{
70+
//TODO transmit behaviour if path empty
71+
//std::cout << "was empty" << std::endl;
72+
}
6873
}
6974
}
7075

src/openfluid/utils/GitProxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace openfluid { namespace utils {
5050
GitProxy::GitProxy()
5151
{
5252
findGitProgram();
53-
53+
m_LocalGitProgram = m_ExecutablePath; // Hotfix to avoid issues under windows with static var def by child class
5454
}
5555

5656

src/openfluid/utils/GitProxy.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@file GitProxy.hpp
3535
3636
@author Jean-Christophe Fabre <jean-christophe.fabre@inra.fr>
37+
@author Armel THÖNI <armel.thoni@inrae.fr>
3738
*/
3839

3940

@@ -54,6 +55,9 @@ class OPENFLUID_API GitProxy : public ProgramProxy<GitProxy>
5455

5556
static void findGitProgram();
5657

58+
protected:
59+
60+
std::string m_LocalGitProgram;
5761

5862
public:
5963

src/openfluid/utils/Process.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@file Process.cpp
3535
3636
@author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37+
@author Armel THÖNI <armel.thoni@inrae.fr>
3738
*/
3839

3940

@@ -157,11 +158,21 @@ bool Process::run()
157158
{
158159
ProcessEnv[Var.first] = Var.second;
159160
}
160-
161+
// Hotfix for windows bug when work dir is empty
162+
std::string WorkDir;
163+
if (m_Cmd.WorkDir.empty())
164+
{
165+
WorkDir = ".";
166+
}
167+
else
168+
{
169+
WorkDir = m_Cmd.WorkDir;
170+
}
161171
boost::process::child BPC(boost::process::exe = m_Cmd.Program,
162172
boost::process::args = m_Cmd.Args,
163-
boost::process::start_dir = m_Cmd.WorkDir,
173+
boost::process::start_dir = WorkDir,
164174
boost::process::std_out > StdOutStr, boost::process::std_err > StdErrStr,
175+
boost::process::shell,
165176
ProcessEnv);
166177

167178
// if out is redirected, create out file
@@ -214,10 +225,14 @@ bool Process::run()
214225
catch(const boost::process::process_error& E)
215226
{
216227
m_ErrorMsg = std::string(E.what());
228+
// TODO for logging purposes
229+
//std::cout << "bp catch! " << E.what() << std::endl;
217230
return false;
218231
}
219232
catch(...)
220233
{
234+
// TODO for logging purposes
235+
//std::cout << "other catch!" << std::endl;
221236
return false;
222237
}
223238

@@ -285,9 +300,19 @@ int Process::system(const Command& Cmd, const Environment& Env)
285300
ProcessEnv[Var.first] = Var.second;
286301
}
287302

303+
std::string WorkDir;
304+
if (Cmd.WorkDir.empty())
305+
{
306+
WorkDir = ".";
307+
}
308+
else
309+
{
310+
WorkDir = Cmd.WorkDir;
311+
}
312+
288313
return boost::process::system(boost::process::exe = Cmd.Program,
289314
boost::process::args = Cmd.Args,
290-
boost::process::start_dir = Cmd.WorkDir,
315+
boost::process::start_dir = WorkDir,
291316
ProcessEnv);
292317
}
293318

0 commit comments

Comments
 (0)