summaryrefslogtreecommitdiff
path: root/test/test_common.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-01-02 15:11:51 -0600
committerDominick Allen <djallen@librehumanitas.org>2025-01-02 15:11:51 -0600
commit87071200872c2450c947047350132aee493033c1 (patch)
tree49109532d9bbd148b4e59043120037684093be33 /test/test_common.cpp
parent16379362c02a2472f00fac49cad62788547c9519 (diff)
Get basic CSV parser operating.
Diffstat (limited to 'test/test_common.cpp')
-rw-r--r--test/test_common.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/test_common.cpp b/test/test_common.cpp
index 07a0088..f272dad 100644
--- a/test/test_common.cpp
+++ b/test/test_common.cpp
@@ -74,7 +74,7 @@ int unlink_cb(const char* fpath, const struct stat* sb_unused, int typeflag, str
return retValue;
}
-FudStatus removeRecursive(const String& path)
+FudStatus removeRecursive(StringView path)
{
if (!path.utf8Valid()) {
return FudStatus::Utf8Invalid;
@@ -82,6 +82,9 @@ FudStatus removeRecursive(const String& path)
if (path.length() < 5) {
return FudStatus::ArgumentInvalid;
}
+ if (not path.nullTerminated()) {
+ return FudStatus::StringInvalid;
+ }
auto prefix{String::makeFromCString("/tmp/").takeOkay()};
auto diffResult = compareMem(path.data(), path.length(), prefix.data(), prefix.length());
if (diffResult.isError()) {
@@ -92,7 +95,8 @@ FudStatus removeRecursive(const String& path)
return FudStatus::ArgumentInvalid;
}
constexpr int maxOpenFd = 64;
- auto status = nftw(path.c_str(), unlink_cb, maxOpenFd, FTW_DEPTH | FTW_PHYS);
+
+ auto status = nftw(reinterpret_cast<const char*>(path.data()), unlink_cb, maxOpenFd, FTW_DEPTH | FTW_PHYS);
if (status == 0) {
return FudStatus::Success;
}
@@ -104,4 +108,15 @@ FudStatus removeRecursive(const String& path)
return FudStatus::Failure;
}
+auto rmFile(StringView filename) -> int
+{
+ auto result = unlink(filename.c_str());
+ if (result == -1) {
+ if (errno == ENOENT) {
+ return 0;
+ }
+ }
+ return result;
+}
+
} // namespace fud