test: tmpd: Make VpnorRoot the parent of ro/rw/prsv/patch
Previously it represented any one of the ro/rw/prsv/patch directories.
It's better if we can deal with all of them at once, so rework the
abstraction.
In the process, the patch exploits other features of
std::experimental::filesystem to increase readability of the code.
Change-Id: I06000709622dd66945cc88cb5333847c69215dc7
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/vpnor/tmpd.cpp b/test/vpnor/tmpd.cpp
index 16a4c2b..6bdfa09 100644
--- a/test/vpnor/tmpd.cpp
+++ b/test/vpnor/tmpd.cpp
@@ -14,16 +14,14 @@
size_t VpnorRoot::write(const std::string &name, const void *data, size_t len)
{
- fs::path path{root};
- path /= name;
+ // write() is for test environment setup - always write to ro section
+ fs::path path = root / "ro" / name;
if (!fs::exists(path))
/* It's not in the ToC */
throw std::invalid_argument(name);
- std::ofstream partitionFile(path.c_str());
- partitionFile.write((const char *)data, len);
- partitionFile.close();
+ std::ofstream(path).write((const char *)data, len);
return len;
}