diff options
Diffstat (limited to 'test/libapt/fileutl_test.cc')
-rw-r--r-- | test/libapt/fileutl_test.cc | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc index 462bdefd9..1d1a1a1b8 100644 --- a/test/libapt/fileutl_test.cc +++ b/test/libapt/fileutl_test.cc @@ -1,19 +1,49 @@ +#include <config.h> + #include <apt-pkg/error.h> #include <apt-pkg/fileutl.h> -#include "assert.h" #include <string> #include <vector> - -#include <stdio.h> -#include <iostream> #include <stdlib.h> +#include <sys/stat.h> +#include "assert.h" -int main(int argc,char *argv[]) +// 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) |