aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils/Filesystem.cpp
diff options
context:
space:
mode:
authorColm Donelan <colm.donelan@arm.com>2023-02-10 15:19:46 +0000
committerColm Donelan <colm.donelan@arm.com>2023-02-10 15:19:46 +0000
commitb5ea589e568d3f56bd868d57c850680f999f83fc (patch)
tree0e9eac9867fc3804c08d5f1b3afacee86e22af3d /src/armnnUtils/Filesystem.cpp
parentaa4f5833bea14bd92b4429c4659d205a81167486 (diff)
downloadarmnn-b5ea589e568d3f56bd868d57c850680f999f83fc.tar.gz
IVGCVSW-7510 Delete temporary files created by DebugTestImpl.
* The test cases that use DebugTestImpl were creating temporary files but not cleaning them up after running. * Refactored FileSystem to extract a common RemoveDirectoryAndContents function. Signed-off-by: Colm Donelan <colm.donelan@arm.com> Change-Id: I35b8d2eeed286742358a9abccbc078493d033902
Diffstat (limited to 'src/armnnUtils/Filesystem.cpp')
-rw-r--r--src/armnnUtils/Filesystem.cpp44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/armnnUtils/Filesystem.cpp b/src/armnnUtils/Filesystem.cpp
index 78f928a874..d09f87ba7f 100644
--- a/src/armnnUtils/Filesystem.cpp
+++ b/src/armnnUtils/Filesystem.cpp
@@ -49,20 +49,8 @@ std::string CreateDirectory(std::string path)
// This line is very unlikely to throw an exception.
fs::path tmpDir = fs::temp_directory_path();
std::string full_path = tmpDir.generic_string() + path;
- if (fs::exists(full_path))
- {
- try
- {
- // This could throw an exception on a multi-user system.
- fs::remove_all(full_path);
- }
- catch (const std::system_error& e)
- {
- std::string error = "Directory exists and cannot be removed. Reason: ";
- error.append(e.what());
- throw armnn::RuntimeException(error);
- }
- }
+ // This could throw a file permission exception.
+ RemoveDirectoryAndContents(full_path);
#if defined(_WIN32)
result = _mkdir(full_path.c_str()); // can be used on Windows
armnn::ConditionalThrow<armnn::RuntimeException>((result == 0), "Was unable to create temporary directory");
@@ -85,7 +73,33 @@ std::string CreateDirectory(std::string path)
return full_path + "/";
}
-FileContents ReadFileContentsIntoString(const std::string path) {
+/**
+ * @brief Remove a directory and its contents.
+ *
+ * Given a directory path delete it's contents and the directory. If the specified directory doesn't exist this
+ * does nothing. If any item cannot be removed this will throw a RuntimeException.
+ *
+ * @param full_path
+ */
+void RemoveDirectoryAndContents(const std::string& path)
+{
+ if (fs::exists(path))
+ {
+ try
+ {
+ // This could throw an exception on a multi-user system.
+ fs::remove_all(path);
+ }
+ catch (const std::system_error& e)
+ {
+ std::string error = "Directory exists and cannot be removed. Reason: ";
+ error.append(e.what());
+ throw armnn::RuntimeException(error);
+ }
+ }
+}
+
+FileContents ReadFileContentsIntoString(const std::string& path) {
if (!fs::exists(path))
{
throw armnn::RuntimeException("Path does not exist: " + path);