summaryrefslogtreecommitdiff
path: root/platform/default/src/mbgl/storage/local_file_source.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/default/src/mbgl/storage/local_file_source.cpp')
-rw-r--r--platform/default/src/mbgl/storage/local_file_source.cpp34
1 files changed, 3 insertions, 31 deletions
diff --git a/platform/default/src/mbgl/storage/local_file_source.cpp b/platform/default/src/mbgl/storage/local_file_source.cpp
index 1bc52fb419..ca2eedc7ba 100644
--- a/platform/default/src/mbgl/storage/local_file_source.cpp
+++ b/platform/default/src/mbgl/storage/local_file_source.cpp
@@ -1,18 +1,10 @@
#include <mbgl/storage/local_file_source.hpp>
#include <mbgl/storage/file_source_request.hpp>
+#include <mbgl/storage/local_file_request.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/thread.hpp>
#include <mbgl/util/url.hpp>
-#include <mbgl/util/util.hpp>
-#include <mbgl/util/io.hpp>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#if defined(_WINDOWS) && !defined(S_ISDIR)
-#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
namespace {
@@ -27,9 +19,8 @@ public:
Impl(ActorRef<Impl>) {}
void request(const std::string& url, ActorRef<FileSourceRequest> req) {
- Response response;
-
if (!acceptsURL(url)) {
+ Response response;
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other,
"Invalid file URL");
req.invoke(&FileSourceRequest::setResponse, response);
@@ -38,27 +29,8 @@ public:
// Cut off the protocol and prefix with path.
const auto path = mbgl::util::percentDecode(url.substr(fileProtocol.size()));
- struct stat buf;
- int result = stat(path.c_str(), &buf);
-
- if (result == 0 && S_ISDIR(buf.st_mode)) {
- response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound);
- } else if (result == -1 && errno == ENOENT) {
- response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound);
- } else {
- auto data = util::readFile(path);
- if (!data) {
- response.error = std::make_unique<Response::Error>(
- Response::Error::Reason::Other,
- std::string("Cannot read file ") + path);
- } else {
- response.data = std::make_shared<std::string>(std::move(*data));
- }
- }
-
- req.invoke(&FileSourceRequest::setResponse, response);
+ requestLocalFile(path, std::move(req));
}
-
};
LocalFileSource::LocalFileSource()