Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

LocalFileSource #6497

Merged
merged 4 commits into from
Sep 30, 2016
Merged

LocalFileSource #6497

merged 4 commits into from
Sep 30, 2016

Conversation

ivovandongen
Copy link
Contributor

Fixes #6273

@ivovandongen ivovandongen added the Core The cross-platform C++ core, aka mbgl label Sep 28, 2016
@ivovandongen ivovandongen self-assigned this Sep 28, 2016
@mention-bot
Copy link

@ivovandongen, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @tmpsantos and @mollymerp to be potential reviewers.

@ivovandongen
Copy link
Contributor Author

@tmpsantos Could you review please (assuming the ci completes)?

I'm not very happy with the name FileFileSource, but couldn't come up with a better one.

@1ec5
Copy link
Contributor

1ec5 commented Sep 29, 2016

I'm not very happy with the name FileFileSource, but couldn't come up with a better one.

How about LocalFileSource?

@1ec5
Copy link
Contributor

1ec5 commented Sep 29, 2016

With these changes, is it still necessary for the default AssetFileSource to know how to handle absolute paths? Also, this iOS/macOS special case can be removed now that file: URLs are supported in core.

@brunoabinader
Copy link
Member

How about LocalFileSource?

I like this one - though we should be aware that the file URI scheme can also point to files on a network location.

@tmpsantos
Copy link
Contributor

How about LocalFileSource?

👍

@ivovandongen ivovandongen changed the title file:// FileSource LocalFileSource Sep 29, 2016
@ivovandongen
Copy link
Contributor Author

How about LocalFileSource?

Seems popular :) I've changed this.

is it still necessary for the default AssetFileSource to know how to handle absolute paths?

I assumed we need to leave it in there now for backwards compatibility.

this iOS/macOS special case can be removed now that file: URLs are supported in core.

Removed

@@ -19,6 +20,12 @@ bool isAssetURL(const std::string& url) {
return std::equal(assetProtocol.begin(), assetProtocol.end(), url.begin());
}

const std::string fileProtocol = "file://";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better avoid this. See for alternatives: #6455


namespace {

std::string toAbsoluteUrl(const std::string& fileName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we use URL on the internal bits rather then Url.

std::string toAbsoluteUrl(const std::string& fileName) {
char buff[PATH_MAX + 1];
char* cwd = getcwd( buff, PATH_MAX + 1 );
return "file:://" + std::string(cwd) + "/test/fixtures/storage/assets/" + fileName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

://

public:
void request(const std::string& url, FileSource::Callback callback) {
//Cut off the protocol
std::string path = mbgl::util::percentDecode(url.substr(7));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this like #6455 with the size a global together with the scheme variable.

loop.run();
}

TEST(LocalFileSource, URLEncoding) {
Copy link
Contributor

@tmpsantos tmpsantos Sep 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake we are no missing anything, can you make a test with a extremely large file name, like memset(filename, 'x', PATH_MAX);

Wondering what would happen if you try to read something you don't have permission to (like /root/foo.txt).

@ivovandongen
Copy link
Contributor Author

@tmpsantos Thanks for the review. I've cleared up all items.

Wondering what would happen if you try to read something you don't have permission to

It returns Response::Error::Reason::Other. Not quite sure how to test this in a platform independent way though.


namespace mbgl {

const char* protocol = "file://";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could go to the anonymous namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Changed it.

#include <sys/stat.h>
#include <unistd.h>

const char* protocol = "file://";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace {

const char* protocol = "file://";
const std::size_t protocolLength = 7;

} // namespace

@1ec5
Copy link
Contributor

1ec5 commented Sep 29, 2016

is it still necessary for the default AssetFileSource to know how to handle absolute paths?

I assumed we need to leave it in there now for backwards compatibility.

True, removing that support might (?) break asset: assets that have been cached, I suppose, and it’s pretty harmless.

@ivovandongen
Copy link
Contributor Author

@tmpsantos I fixed the valgrind errors. If all else is good, could you press the review button?

Copy link
Contributor

@tmpsantos tmpsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for [core]

@tobrun
Copy link
Member

tobrun commented Sep 30, 2016

:shipit:

@ivovandongen ivovandongen merged commit d4888cb into master Sep 30, 2016
@ivovandongen ivovandongen deleted the 6273-fs-filesource branch September 30, 2016 12:57
@ericpalakovichcarr
Copy link

I just wanted to say to @ivovandongen, thank you! Oh, and also @1ec5 and the rest of the mapbox team as well 👍

@zugaldia
Copy link
Member

cc: @cammace this looks like a good candidate for a new sample, or a required update to https://www.mapbox.com/android-sdk/examples/custom-raster/.

@SeanChristopherConway
Copy link

I am using ios SDK 3.4.0-beta.6 and am not able to use the file:// style to load my style JSON or in the tiles section of my sources in the style.json. When I use asset:// for the style it loads, but neither asset nor file seem to work within the styles section.

@1ec5
Copy link
Contributor

1ec5 commented Jan 16, 2017

It should be possible to use an absolute file: URL as an MGLMapView’s style URL. But I’m not sure if it’s supposed to be possible to use a file: URL inside the JSON file itself. In any event, this closed PR likely isn’t being watched by folks who know the answer for sure, so please open a new issue, ideally with more details about your style JSON.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants