diff options
author | Michael Vogt <mvo@ubuntu.com> | 2014-04-10 09:15:03 +0200 |
---|---|---|
committer | Michael Vogt <mvo@ubuntu.com> | 2014-04-10 09:15:03 +0200 |
commit | f659e5d5f97350133671c48101fb399ddb9fcd42 (patch) | |
tree | 2e619308ff0b07f5ebe9d563aa8b9818c8653fa9 /test/libapt | |
parent | a8f438942457e4476ac7c6dab12a115fcebc8315 (diff) | |
parent | db5bf949ed796395d281474c49033f882e73f3a9 (diff) |
Merge remote-tracking branch 'mvo/bugfix/lp1304657-perms' into debian/sid
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/fileutl_test.cc | 31 |
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) |