diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-16 11:35:41 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-08-24 16:47:08 +0200 |
commit | 2d8a35e2eb9b93aafe0a86e45bb4cb0abf8b6c3a (patch) | |
tree | e422245cb8087a86ef9566f588e33c64f3305eba /src/basic/fs-util.c | |
parent | 128beb102e3f081742727ca685ca67d68cd382dd (diff) |
fs-util,test: add helper to remove tempfiles
This simplifies the use of tempfiles in tests and fixes "leaked"
temporary files in test-fileio, test-catalog, test-conf-parser.
Not the whole tree is converted.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r-- | src/basic/fs-util.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 4e74cb7b0..24c447036 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -1081,6 +1081,15 @@ int access_fd(int fd, int mode) { return r; } +void unlink_tempfilep(char (*p)[]) { + /* If the file is created with mkstemp(), it will (almost always) + * change the suffix. Treat this as a sign that the file was + * successfully created. We ignore both the rare case where the + * original suffix is used and unlink failures. */ + if (!endswith(*p, ".XXXXXX")) + (void) unlink(*p); +} + int unlinkat_deallocate(int fd, const char *name, int flags) { _cleanup_close_ int truncate_fd = -1; struct stat st; |