stat-util: unify code that checks whether something is a regular file

Let's add a common implementation for regular file checks, that are
careful to return the right error code (EISDIR/EISLNK/EBADFD) when we
are encountering a wrong file node.
This commit is contained in:
Lennart Poettering
2018-02-20 15:39:31 +01:00
parent 9c66f52813
commit 3cc4411403
8 changed files with 73 additions and 58 deletions
+4 -2
View File
@@ -37,6 +37,7 @@
#include "import-common.h"
#include "missing.h"
#include "ratelimit.h"
#include "stat-util.h"
#include "string-util.h"
#include "util.h"
@@ -319,8 +320,9 @@ int raw_export_start(RawExport *e, const char *path, int fd, ImportCompressType
if (fstat(sfd, &e->st) < 0)
return -errno;
if (!S_ISREG(e->st.st_mode))
return -ENOTTY;
r = stat_verify_regular(&e->st);
if (r < 0)
return r;
/* Try to take a reflink snapshot of the file, if we can t make the export atomic */
tfd = reflink_snapshot(sfd, path);