Skip to content

Commit 2ab8c55

Browse files
committed
Fixed bug in DataHandler regarding checking mime type of unexisting files.
1 parent 20472fa commit 2ab8c55

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/DataHandler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "DataHandler.h"
22

33
#include <linux/limits.h>
4+
#include <fcntl.h>
45
#include <unistd.h>
56

67
/*
@@ -55,6 +56,14 @@ DataHandler::resource DataHandler::read_resource(std::string path, std::string c
5556
path = cwd + path;
5657
this->logger->debug("Checking resource at: " + path);
5758

59+
// first check if such a file even exists
60+
int fd = open(path.c_str(), O_RDONLY);
61+
if (fd < 0) {
62+
char * err = std::strerror(errno);
63+
throw DataHandler::FileNotFound("Error while reading file contents at " + path + ": " + std::string(err ? err : "unknown error"));
64+
}
65+
close(fd);
66+
5867
// check mime type of resource
5968
DataHandler::Exec runner;
6069
std::string args[2] = { "/usr/bin/file", path };

0 commit comments

Comments
 (0)