From bc6484912ebb3db2ac9637abebdeadd28f6d84c3 Mon Sep 17 00:00:00 2001 From: Romain Geissler Date: Fri, 3 Jun 2011 21:09:14 +0200 Subject: [PATCH] Fileops: Added gitfo_isfile. Conflicts: src/fileops.c --- src/fileops.c | 21 ++++++++++++++++++++- src/fileops.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index 409d1cb5a..11634c263 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -131,7 +131,26 @@ int gitfo_isdir(const char *path) return git__throw(GIT_ENOTFOUND, "%s does not exist", path); if (!S_ISDIR(st.st_mode)) - return git__throw(GIT_ENOTFOUND, "%s is a file", path); + return git__throw(GIT_ENOTFOUND, "%s is not a directory", path); + + return GIT_SUCCESS; +} + +int gitfo_isfile(const char *path) +{ + struct stat st; + int stat_error; + + if (!path) + return git__throw(GIT_ENOTFOUND, "No path given to gitfo_isfile"); + + stat_error = gitfo_stat(path, &st); + + if (stat_error < GIT_SUCCESS) + return git__throw(GIT_ENOTFOUND, "%s does not exist", path); + + if (!S_ISREG(st.st_mode)) + return git__throw(GIT_ENOTFOUND, "%s is not a file", path); return GIT_SUCCESS; } diff --git a/src/fileops.h b/src/fileops.h index 1b70fc836..aa225dca6 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -67,6 +67,7 @@ extern int gitfo_creat(const char *path, int mode); extern int gitfo_creat_force(const char *path, int mode); extern int gitfo_mktemp(char *path_out, const char *filename); extern int gitfo_isdir(const char *path); +extern int gitfo_isfile(const char *path); extern int gitfo_mkdir_recurs(const char *path, int mode); extern int gitfo_mkdir_2file(const char *path); #define gitfo_close(fd) close(fd)