mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
{libutil,libstore}: Factor out chmodIfNeeded
Using std::filesystem::path directly because we need .c_str() anyway to interact with chmod. Path/string views don't have to be null-terminated.
This commit is contained in:
parent
c99edc840c
commit
82f337de10
4 changed files with 57 additions and 4 deletions
|
@ -275,4 +275,30 @@ TEST(makeParentCanonical, root)
|
|||
{
|
||||
ASSERT_EQ(makeParentCanonical("/"), "/");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* chmodIfNeeded
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(chmodIfNeeded, works)
|
||||
{
|
||||
auto [autoClose_, tmpFile] = nix::createTempFile();
|
||||
auto deleteTmpFile = AutoDelete(tmpFile);
|
||||
|
||||
auto modes = std::vector<mode_t>{0755, 0644, 0422, 0600, 0777};
|
||||
for (mode_t oldMode : modes) {
|
||||
for (mode_t newMode : modes) {
|
||||
chmod(tmpFile.c_str(), oldMode);
|
||||
bool permissionsChanged = false;
|
||||
ASSERT_NO_THROW(permissionsChanged = chmodIfNeeded(tmpFile, newMode));
|
||||
ASSERT_EQ(permissionsChanged, oldMode != newMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(chmodIfNeeded, nonexistent)
|
||||
{
|
||||
ASSERT_THROW(chmodIfNeeded("/schnitzel/darmstadt/pommes", 0755), SysError);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue