Commit 508ba227 authored by Max Kellermann's avatar Max Kellermann

archive/ArchiveLookup: use class FileInfo

parent fa13648f
...@@ -20,11 +20,10 @@ ...@@ -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, ...@@ -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, ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment