Loading init/persistent_properties.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -236,6 +236,9 @@ void WritePersistentProperty(const std::string& name, const std::string& value) persistent_properties->mutable_properties()->end(), [&name](const auto& record) { return record.name() == name; }); if (it != persistent_properties->mutable_properties()->end()) { if (it->value() == value) { return; } it->set_name(name); it->set_value(value); } else { Loading init/persistent_properties_test.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ #include "persistent_properties.h" #include <errno.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <vector> Loading Loading @@ -155,6 +158,31 @@ TEST(persistent_properties, UpdatePropertyBadParse) { EXPECT_FALSE(it == read_back_properties.properties().end()); } TEST(persistent_properties, NopUpdateDoesntWriteFile) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); persistent_property_filename = tf.path; auto last_modified = [&tf]() -> time_t { struct stat buf; EXPECT_EQ(fstat(tf.fd, &buf), 0); return buf.st_mtime; }; std::vector<std::pair<std::string, std::string>> persistent_properties = { {"persist.sys.locale", "en-US"}, {"persist.sys.timezone", "America/Los_Angeles"}, }; ASSERT_RESULT_OK( WritePersistentPropertyFile(VectorToPersistentProperties(persistent_properties))); time_t t = last_modified(); sleep(2); WritePersistentProperty("persist.sys.locale", "en-US"); // Ensure that the file was not modified ASSERT_EQ(last_modified(), t); } TEST(persistent_properties, RejectNonPersistProperty) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); Loading Loading
init/persistent_properties.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -236,6 +236,9 @@ void WritePersistentProperty(const std::string& name, const std::string& value) persistent_properties->mutable_properties()->end(), [&name](const auto& record) { return record.name() == name; }); if (it != persistent_properties->mutable_properties()->end()) { if (it->value() == value) { return; } it->set_name(name); it->set_value(value); } else { Loading
init/persistent_properties_test.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ #include "persistent_properties.h" #include <errno.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <vector> Loading Loading @@ -155,6 +158,31 @@ TEST(persistent_properties, UpdatePropertyBadParse) { EXPECT_FALSE(it == read_back_properties.properties().end()); } TEST(persistent_properties, NopUpdateDoesntWriteFile) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); persistent_property_filename = tf.path; auto last_modified = [&tf]() -> time_t { struct stat buf; EXPECT_EQ(fstat(tf.fd, &buf), 0); return buf.st_mtime; }; std::vector<std::pair<std::string, std::string>> persistent_properties = { {"persist.sys.locale", "en-US"}, {"persist.sys.timezone", "America/Los_Angeles"}, }; ASSERT_RESULT_OK( WritePersistentPropertyFile(VectorToPersistentProperties(persistent_properties))); time_t t = last_modified(); sleep(2); WritePersistentProperty("persist.sys.locale", "en-US"); // Ensure that the file was not modified ASSERT_EQ(last_modified(), t); } TEST(persistent_properties, RejectNonPersistProperty) { TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); Loading