Skip to content

Commit

Permalink
- add option to change default temp dir used
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Sep 22, 2022
1 parent 97b17e4 commit 0826e5d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.18
0.2.19
17 changes: 16 additions & 1 deletion src/combine/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@

LIBCOMBINE_CPP_NAMESPACE_USE

std::string Util::mDefaultTempDir = ".";

std::string
Util::getDefaultTempDir()
{
return mDefaultTempDir;
}

void
Util::setDefaultTempDir(const std::string& defaultDir)
{
mDefaultTempDir = defaultDir;
}


std::string
Util::getTempPath()
{
char *tmpDir = getenv("TMP");
if (tmpDir != NULL) return tmpDir;
tmpDir = getenv("TEMP");
if (tmpDir != NULL) return tmpDir;
return ".";
return mDefaultTempDir;
}

std::string
Expand Down
18 changes: 17 additions & 1 deletion src/combine/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ class LIBCOMBINE_EXTERN Util
*/
static bool removeFileOrFolder(const std::string& path);

/**
* @brief Get the Default Temp Dir object
*
* @return std::string of the default directory
*/
static std::string getDefaultTempDir();

/**
* @brief Set the Default Temp Dir object
*
* @param defaultDir the default directory
*/
static void setDefaultTempDir(const std::string& defaultDir);

private:

Expand All @@ -118,7 +131,10 @@ class LIBCOMBINE_EXTERN Util
*/
static size_t getExtensionIndex(const char *fileName);


/**
* the default temp dir (defaults to ".")
*/
static std::string mDefaultTempDir;
};

LIBCOMBINE_CPP_NAMESPACE_END
Expand Down
9 changes: 9 additions & 0 deletions src/test/util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ SCENARIO("utility methods", "[combine][util]")
REQUIRE(KnownFormats::isFormat("sbml",
KnownFormats::guessFormat(getTestFile("test-data/BorisEJB.xml"))));
}

GIVEN("The default dir is changed")
{
std::string defaultDir = Util::getDefaultTempDir();
REQUIRE(defaultDir.empty() == false);
Util::setDefaultTempDir("/tmp/");
REQUIRE(Util::getDefaultTempDir() == "/tmp/");
Util::setDefaultTempDir(defaultDir);
}
}

0 comments on commit 0826e5d

Please sign in to comment.