archive/ArchiveLookup: use class FileInfo

This commit is contained in:
Max Kellermann 2019-05-31 18:51:16 +02:00
parent fa13648f2c
commit 508ba22789

View File

@ -20,11 +20,10 @@
#include "ArchiveLookup.hxx" #include "ArchiveLookup.hxx"
#include "ArchiveDomain.hxx" #include "ArchiveDomain.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "fs/FileInfo.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <errno.h>
gcc_pure gcc_pure
static char * static char *
@ -58,19 +57,16 @@ archive_lookup(char *pathname, const char **archive,
char *slash = nullptr; char *slash = nullptr;
while (true) { while (true) {
//try to stat if its real directory try {
struct stat st_info; //try to stat if its real directory
if (stat(pathname, &st_info) == -1) { const FileInfo file_info(Path::FromFS(pathname));
int e = errno;
if (e != ENOTDIR)
throw FormatErrno(e, "Failed to stat %s", pathname);
} else {
//is something found ins original path (is not an archive) //is something found ins original path (is not an archive)
if (slash == nullptr) if (slash == nullptr)
return false; return false;
//its a file ? //its a file ?
if (S_ISREG(st_info.st_mode)) { if (file_info.IsRegular()) {
//so the upper should be file //so the upper should be file
*archive = pathname; *archive = pathname;
*inpath = slash + 1; *inpath = slash + 1;
@ -84,6 +80,9 @@ archive_lookup(char *pathname, const char **archive,
pathname); pathname);
return false; return false;
} }
} catch (const std::system_error &e) {
if (!IsPathNotFound(e))
throw;
} }
//find one dir up //find one dir up