return true;
}
+bool removeFile(const std::string& path)
+{
+ LOGD(path << ": exists, removing.");
+ if (::remove(path.c_str())) {
+ if (errno != ENOENT) {
+ LOGE(path << ": failed to delete: " << ::strerror(errno));
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool isCharDevice(const std::string& path)
{
struct stat s;
bool saveFileContent(const std::string& path, const std::string& content);
/**
+ * Remove file
+ */
+bool removeFile(const std::string& path);
+
+/**
* Checks if a char device exists
*/
bool isCharDevice(const std::string& path);
const std::string HOST_ID = "host";
const std::string ZONE_TEMPLATE_CONFIG_PATH = "template.conf";
+const std::string ENABLED_FILE_NAME = "enabled";
const boost::regex ZONE_NAME_REGEX("~NAME~");
const boost::regex ZONE_IP_THIRD_OCTET_REGEX("~IP~");
this, id, _1));
mZones.insert(ZoneMap::value_type(id, std::move(c)));
+
+ // after zone is created successfully, put a file informing that zones are enabled
+ if (mZones.size() == 1) {
+ if (!utils::saveFileContent(
+ utils::createFilePath(mConfig.zonesPath, "/", ENABLED_FILE_NAME), "")) {
+ throw ZoneOperationException(ENABLED_FILE_NAME + ": cannot create.");
+ }
+ }
}
void ZonesManager::destroyZone(const std::string& zoneId)
// TODO give back the focus
it->second->setDestroyOnExit();
mZones.erase(it);
+
+ if (mZones.size() == 0) {
+ if (!utils::removeFile(utils::createFilePath(mConfig.zonesPath, "/", ENABLED_FILE_NAME))) {
+ LOGE("Failed to remove enabled file.");
+ }
+ }
}
void ZonesManager::focus(const std::string& zoneId)
boost::filesystem::remove(FILE_PATH_RANDOM, ec);
}
+BOOST_AUTO_TEST_CASE(RemoveFileTest)
+{
+ BOOST_REQUIRE(saveFileContent(FILE_PATH_RANDOM, FILE_CONTENT));
+ BOOST_REQUIRE(removeFile(FILE_PATH_RANDOM));
+ BOOST_REQUIRE(!boost::filesystem::exists(FILE_PATH_RANDOM));
+}
+
BOOST_AUTO_TEST_CASE(MountPointTest)
{
bool result;