3 #include <apt-pkg/error.h>
4 #include <apt-pkg/fileutl.h>
13 // regression test for permission bug LP: #1304657
15 TestFileFdOpenPermissions(mode_t a_umask
, mode_t ExpectedFilePermission
)
19 static const char* fname
= "test.txt";
22 f
.Open(fname
, FileFd::ReadWrite
|FileFd::Atomic
);
24 if (stat(fname
, &buf
) < 0)
26 _error
->Errno("stat", "failed to stat");
31 equals(buf
.st_mode
& 0777, ExpectedFilePermission
);
37 std::vector
<std::string
> files
;
39 if (TestFileFdOpenPermissions(0002, 0664) == false ||
40 TestFileFdOpenPermissions(0022, 0644) == false ||
41 TestFileFdOpenPermissions(0077, 0600) == false ||
42 TestFileFdOpenPermissions(0026, 0640) == false)
48 files
= Glob("*.lst");
49 if (files
.size() != 1)
56 files
= Glob("xxxyyyzzz");
57 if (files
.size() != 0 || _error
->PendingError())
63 // many matches (number is a bit random)
65 if (files
.size() < 10)
73 equals(GetTempDir(), "/tmp");
75 setenv("TMPDIR", "", 1);
76 equals(GetTempDir(), "/tmp");
78 setenv("TMPDIR", "/not-there-no-really-not", 1);
79 equals(GetTempDir(), "/tmp");
81 setenv("TMPDIR", "/usr", 1);
82 equals(GetTempDir(), "/usr");