1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-13 20:41:04 +01:00

libutil: Get rid of restartableSourceFromFactory

Instead we can just seek back in the file - duh. Also this makes use
of the anonymous temp file facility, since that is much safer (no need
window where the we don't have an open file descriptor for it).
This commit is contained in:
Sergei Zimmerman 2025-12-01 04:21:27 +03:00
parent 4ad272015e
commit 4b3536e092
No known key found for this signature in database
4 changed files with 43 additions and 73 deletions

View file

@ -398,4 +398,20 @@ TEST(createAnonymousTempFile, works)
EXPECT_EQ(source.drain(), "testtest");
}
/* ----------------------------------------------------------------------------
* FdSource
* --------------------------------------------------------------------------*/
TEST(FdSource, restartWorks)
{
auto fd = createAnonymousTempFile();
writeFull(fd.get(), "hello world");
lseek(fd.get(), 0, SEEK_SET);
FdSource source{fd.get()};
EXPECT_EQ(source.drain(), "hello world");
source.restart();
EXPECT_EQ(source.drain(), "hello world");
EXPECT_EQ(source.drain(), "");
}
} // namespace nix