|
KiCad PCB EDA Suite
|
#include <file_utils.h>
Public Member Functions | |
| SCOPED_TEMP_DIR (const wxString &aPrefix) | |
| Create a temporary directory with a unique name based on the given prefix. | |
| ~SCOPED_TEMP_DIR () | |
| SCOPED_TEMP_DIR (const SCOPED_TEMP_DIR &)=delete | |
| SCOPED_TEMP_DIR & | operator= (const SCOPED_TEMP_DIR &)=delete |
| const std::filesystem::path & | Path () const |
| Get the path to the temporary directory as a std::filesystem::path. | |
| wxString | PathStr () const |
| Get the path to the temporary directory as a wxString. | |
| wxString | ChildPathStr (const wxString &aName) const |
| Get the path to a direct child of the temporary directory as a wxString, without creating the child. | |
| std::filesystem::path | CreateChildDir (const wxString &aName) const |
| Create and return the path to a direct child directory. | |
| wxString | CreateChildDirStr (const wxString &aName) const |
| Create and return the path to a direct child directory as a wxString. | |
| std::filesystem::path | CreateChildFile (const wxString &aName) const |
| Create and return the path to a direct child file. | |
| wxString | CreateChildFileStr (const wxString &aName) const |
| Create and return the path to a direct child file as a wxString. | |
| void | Retain () |
| Keep this directory after all. | |
Static Public Member Functions | |
| static bool | AnyTempDirRetained () |
Private Attributes | |
| std::filesystem::path | m_path |
| bool | m_keep = false |
Static Private Attributes | |
| static bool | s_anyTempDirRetained = false |
Definition at line 37 of file file_utils.h.
| SCOPED_TEMP_DIR::SCOPED_TEMP_DIR | ( | const wxString & | aPrefix | ) |
Create a temporary directory with a unique name based on the given prefix.
The directory is removed on destruction unless the environment variable KICAD_QA_KEEP_TEMP, when interpreted as a comma-separated list of prefixes, contains the given prefix. The special value "ALL" will keep all temporary directories created by this class.
| aPrefix | Prefix for the temporary directory name |
Definition at line 103 of file file_utils.cpp.
References createTempDir(), m_keep, m_path, s_anyTempDirRetained, and shouldKeepTemp().
Referenced by operator=(), and SCOPED_TEMP_DIR().
| SCOPED_TEMP_DIR::~SCOPED_TEMP_DIR | ( | ) |
Definition at line 112 of file file_utils.cpp.
References m_keep, m_path, and reportTempDir().
|
delete |
References SCOPED_TEMP_DIR().
|
inlinestatic |
Definition at line 120 of file file_utils.h.
References s_anyTempDirRetained.
Referenced by KI_TEST::SCOPED_PROCESS_TEMP_DIR::~SCOPED_PROCESS_TEMP_DIR().
| wxString SCOPED_TEMP_DIR::ChildPathStr | ( | const wxString & | aName | ) | const |
Get the path to a direct child of the temporary directory as a wxString, without creating the child.
Note you don't need a ChildPath() as you can just use Path() / "childname" to get a std::filesystem::path.
Also note that this is the easiest/less-racy way to get a temp file with a given extension rather than using wxFileName::CreateTempFileName() and then renaming it, which is easy to leak or race.
| aName | Name of the child file or directory, must be a single path component |
| std::invalid_argument | if aName is not a single path component |
Definition at line 139 of file file_utils.cpp.
References m_path.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and RasterizePdfCountDark().
| std::filesystem::path SCOPED_TEMP_DIR::CreateChildDir | ( | const wxString & | aName | ) | const |
Create and return the path to a direct child directory.
| std::runtime_error | if the directory cannot be created |
Definition at line 145 of file file_utils.cpp.
References m_path.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CreateChildDirStr(), and KI_TEST::LoadAndTestFootprintFile().
| wxString SCOPED_TEMP_DIR::CreateChildDirStr | ( | const wxString & | aName | ) | const |
Create and return the path to a direct child directory as a wxString.
| std::runtime_error | if the directory cannot be created |
Definition at line 156 of file file_utils.cpp.
References CreateChildDir().
Referenced by BOOST_FIXTURE_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and BOOST_FIXTURE_TEST_CASE().
| std::filesystem::path SCOPED_TEMP_DIR::CreateChildFile | ( | const wxString & | aName | ) | const |
Create and return the path to a direct child file.
| std::runtime_error | if the file cannot be created |
Definition at line 162 of file file_utils.cpp.
References m_path.
Referenced by CreateChildFileStr().
| wxString SCOPED_TEMP_DIR::CreateChildFileStr | ( | const wxString & | aName | ) | const |
Create and return the path to a direct child file as a wxString.
| std::runtime_error | if the file cannot be created |
Definition at line 174 of file file_utils.cpp.
References CreateChildFile().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
delete |
References SCOPED_TEMP_DIR().
|
inline |
Get the path to the temporary directory as a std::filesystem::path.
Definition at line 59 of file file_utils.h.
References m_path.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and KI_TEST::LoadAndTestBoardFile().
|
inline |
Get the path to the temporary directory as a wxString.
Definition at line 62 of file file_utils.h.
References m_path.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
| void SCOPED_TEMP_DIR::Retain | ( | ) |
Keep this directory after all.
It is nearly always wrong to use this in actual tests, but it can be helpful for debugging purposes (e.g. conditionally keeping the directory if a certain test fails).
If a SCOPED_PROCESS_TEMP_DIR is in use, the process-wide temporary directory is kept as well.
Definition at line 129 of file file_utils.cpp.
References m_keep, m_path, reportTempDir(), and s_anyTempDirRetained.
|
private |
Definition at line 124 of file file_utils.h.
Referenced by Retain(), SCOPED_TEMP_DIR(), and ~SCOPED_TEMP_DIR().
|
private |
Definition at line 123 of file file_utils.h.
Referenced by ChildPathStr(), CreateChildDir(), CreateChildFile(), Path(), PathStr(), Retain(), SCOPED_TEMP_DIR(), and ~SCOPED_TEMP_DIR().
|
staticprivate |
Definition at line 127 of file file_utils.h.
Referenced by AnyTempDirRetained(), Retain(), and SCOPED_TEMP_DIR().