summaryrefslogtreecommitdiff
path: root/indra/test/namedtempfile.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/test/namedtempfile.h')
-rw-r--r--indra/test/namedtempfile.h31
1 files changed, 21 insertions, 10 deletions
diff --git a/indra/test/namedtempfile.h b/indra/test/namedtempfile.h
index c215c50f3f..525a35000d 100644
--- a/indra/test/namedtempfile.h
+++ b/indra/test/namedtempfile.h
@@ -65,8 +65,7 @@ public:
boost::filesystem::remove(mPath);
}
- // On Windows, path::native() returns a wstring
- std::string getName() const { return ll_convert<std::string>(mPath.native()); }
+ std::string getName() const { return mPath.string(); }
void peep()
{
@@ -78,21 +77,33 @@ public:
std::cout << "---\n";
}
+ static boost::filesystem::path temp_path(const std::string_view& pfx="",
+ const std::string_view& sfx="")
+ {
+ // This variable is set by GitHub actions and is the recommended place
+ // to put temp files belonging to an actions job.
+ const char* RUNNER_TEMP = getenv("RUNNER_TEMP");
+ boost::filesystem::path tempdir{
+ // if RUNNER_TEMP is set and not empty
+ (RUNNER_TEMP && *RUNNER_TEMP)?
+ boost::filesystem::path(RUNNER_TEMP) : // use RUNNER_TEMP if available
+ boost::filesystem::temp_directory_path()}; // else canonical temp dir
+ boost::filesystem::path tempname{
+ // use filename template recommended by unique_path() doc, but
+ // with underscores instead of hyphens: some use cases involve
+ // temporary Python scripts
+ tempdir / stringize(pfx, "%%%%_%%%%_%%%%_%%%%", sfx) };
+ return boost::filesystem::unique_path(tempname);
+ }
+
protected:
void createFile(const std::string_view& pfx,
const Streamer& func,
const std::string_view& sfx)
{
// Create file in a temporary place.
- boost::filesystem::path tempname{
- boost::filesystem::temp_directory_path() /
- // unique_path() recommended template, but with underscores
- // instead of hyphens: some use cases involve temporary Python
- // scripts
- stringize(pfx, "%%%%_%%%%_%%%%_%%%%", sfx) };
- mPath = boost::filesystem::unique_path(tempname);
+ mPath = temp_path(pfx, sfx);
boost::filesystem::ofstream out{ mPath };
-
// Write desired content.
func(out);
}