summaryrefslogtreecommitdiff
path: root/test/libapt/fileutl_test.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-04-10 09:39:35 +0200
committerMichael Vogt <mvo@debian.org>2014-04-10 09:39:35 +0200
commita1a253e8be978998b66af62240a25864db2cc694 (patch)
tree485efb6b77d063b08045153478e704e804242b7e /test/libapt/fileutl_test.cc
parent4c3722e3a74f183b331b0a782017ae442ca143fb (diff)
parent5ff678f7a22bb3206f5e46fcbdd00e56cb44b99e (diff)
Merge branch 'debian/sid' into ubuntu/master
Diffstat (limited to 'test/libapt/fileutl_test.cc')
-rw-r--r--test/libapt/fileutl_test.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 8da832ba9..1d1a1a1b8 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -6,13 +6,44 @@
#include <string>
#include <vector>
#include <stdlib.h>
+#include <sys/stat.h>
#include "assert.h"
+// regression test for permission bug LP: #1304657
+static bool
+TestFileFdOpenPermissions(mode_t a_umask, mode_t ExpectedFilePermission)
+{
+ FileFd f;
+ struct stat buf;
+ static const char* fname = "test.txt";
+
+ umask(a_umask);
+ f.Open(fname, FileFd::ReadWrite|FileFd::Atomic);
+ f.Close();
+ if (stat(fname, &buf) < 0)
+ {
+ _error->Errno("stat", "failed to stat");
+ _error->DumpErrors();
+ return false;
+ }
+ unlink(fname);
+ equals(buf.st_mode & 0777, ExpectedFilePermission);
+ return true;
+}
+
int main()
{
std::vector<std::string> files;
+ if (TestFileFdOpenPermissions(0002, 0664) == false ||
+ TestFileFdOpenPermissions(0022, 0644) == false ||
+ TestFileFdOpenPermissions(0077, 0600) == false ||
+ TestFileFdOpenPermissions(0026, 0640) == false)
+ {
+ return 1;
+ }
+
// normal match
files = Glob("*.lst");
if (files.size() != 1)