Remove some duplicate code

This commit is contained in:
Eelco Dolstra 2014-10-03 22:37:51 +02:00 committed by Ludovic Courtès
parent c957422835
commit c2b65dd197
3 changed files with 14 additions and 6 deletions

View File

@ -301,12 +301,8 @@ static void findRoots(StoreAPI & store, const Path & path, unsigned char type, R
{
try {
if (type == DT_UNKNOWN) {
struct stat st = lstat(path);
if (S_ISDIR(st.st_mode)) type = DT_DIR;
else if (S_ISLNK(st.st_mode)) type = DT_LNK;
else if (S_ISREG(st.st_mode)) type = DT_REG;
}
if (type == DT_UNKNOWN)
type = getFileType(path);
if (type == DT_DIR) {
for (auto & i : readDirectory(path))

View File

@ -223,6 +223,16 @@ DirEntries readDirectory(const Path & path)
}
unsigned char getFileType(const Path & path)
{
struct stat st = lstat(path);
if (S_ISDIR(st.st_mode)) return DT_DIR;
if (S_ISLNK(st.st_mode)) return DT_LNK;
if (S_ISREG(st.st_mode)) return DT_REG;
return DT_UNKNOWN;
}
string readFile(int fd)
{
struct stat st;

View File

@ -77,6 +77,8 @@ typedef vector<DirEntry> DirEntries;
DirEntries readDirectory(const Path & path);
unsigned char getFileType(const Path & path);
/* Read the contents of a file into a string. */
string readFile(int fd);
string readFile(const Path & path, bool drain = false);