summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-11-02 16:02:44 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2015-11-04 18:42:28 +0100
commitcd46d4ebd33e74ee53bbc73dcdb7fe1d4d006558 (patch)
treeebb72d38d8d7b21849cba5d6b2501cd0e1d94cba /test/libapt
parent2f91076de326a0dee067659381a9c4cf745f0efe (diff)
ensure FileFd doesn't try to open /dev/null as atomic and co
The wrapping will fail in the best case and actually end up deleting /dev/null in the worst case. Given that there is no point in trying to write atomically to /dev/null as you can't read from it again just ignore these flags if higher level code ends up trying to use them on /dev/null. Git-Dch: Ignore
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/fileutl_test.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index b42261716..2bd090e5e 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -298,3 +298,33 @@ TEST(FileUtlTest, flAbsPath)
res = chdir(cwd.c_str());
EXPECT_EQ(res, 0);
}
+
+static void TestDevNullFileFd(unsigned int const filemode)
+{
+ FileFd f("/dev/null", filemode);
+ EXPECT_FALSE(f.Failed());
+ EXPECT_TRUE(f.IsOpen());
+ EXPECT_TRUE(f.IsOpen());
+
+ std::string test = "This is a test!\n";
+ EXPECT_TRUE(f.Write(test.c_str(), test.size()));
+ EXPECT_TRUE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+
+ f.Close();
+ EXPECT_FALSE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+}
+TEST(FileUtlTest, WorkingWithDevNull)
+{
+ TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create);
+ TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Empty);
+ TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive);
+ TestDevNullFileFd(FileFd::WriteOnly | FileFd::Atomic);
+ TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Atomic);
+ // short-hands for ReadWrite with these modes
+ TestDevNullFileFd(FileFd::WriteEmpty);
+ TestDevNullFileFd(FileFd::WriteAny);
+ TestDevNullFileFd(FileFd::WriteTemp);
+ TestDevNullFileFd(FileFd::WriteAtomic);
+}