Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
d0a37e2
created schema init sql files
sdf-jkl Jun 1, 2025
fcd3216
Changed mdbook to include files
sdf-jkl Jun 1, 2025
d4e8eae
Add .sql tiles for mbtiles to tests/fixtures/{files, mbtiles}
Jun 2, 2025
5443988
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2025
6a6244b
Update quick-start guides
Jun 4, 2025
11de2a3
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 4, 2025
6323bd9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2025
faa3334
Update docs mbtiles-meta page
Jun 4, 2025
9f5a1a8
Update .sql files to remove sqlite_stat1 entries
Jun 4, 2025
f2a4898
Update .sql files to refactor multiple inserts into one
Jun 4, 2025
2dde537
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 4, 2025
d94edad
Update summary.rs unit tests
Jun 16, 2025
747c602
Update mbtiles/src/summary.rs
sdf-jkl Jun 17, 2025
a0a607e
Update mbtiles copy docs
Jun 18, 2025
17fa5d7
update mbtile sql files
Jun 18, 2025
34580b6
Update mbtles::summary test
Jun 18, 2025
e1800da
Undo change world_cities.sql
Jun 18, 2025
8357d7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2025
4b54679
Update world_cities.sql
Jun 18, 2025
89bea5e
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 18, 2025
051f27d
update validation.rs tests
Jun 18, 2025
c06874a
Update docs/src/mbtiles-meta.md
sdf-jkl Jun 18, 2025
e77856d
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 18, 2025
a5afee2
Revert "update mbtile sql files"
Jun 18, 2025
3505c3f
Update metadata.rs tests
Jun 18, 2025
c8a1966
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2025
1174483
Remove mbtiles files
Jun 18, 2025
d905d38
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 18, 2025
3d69c49
Merge branch 'maplibre:main' into generate-mbtiles-on-the-fly
sdf-jkl Jun 18, 2025
830e880
Update metadata.rs unit tests and normalized .sql files
Jun 26, 2025
ed72b04
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 26, 2025
85298d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2025
1c4c820
Update metadata.rs and pool.rs unit tests
Jun 26, 2025
ae68f0c
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 26, 2025
f9e83b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2025
2b0a026
Update patches.rs unit tests
Jun 26, 2025
1bf7fa3
Fix newline escape in sqlx
Jun 26, 2025
d6a6d45
Update copier.rs unit tests
Jun 26, 2025
352a0d9
Update root.rs unit test
Jun 27, 2025
413e638
Fix pool.rs unwrap logic
Jun 27, 2025
7035a4f
Fix copier.rs unit tests unwrap logic
Jun 27, 2025
1b395ea
Fix metadata.rs unit tests unwrap logic
Jun 27, 2025
f7cb4ac
Fix summary.rs unwrap logic
Jun 27, 2025
87a56b7
Fix patcher.rs unwrap logic
Jun 27, 2025
7d0160b
Fix validation.rs unwrap logic
Jun 27, 2025
398a7cb
cargo fmt
Jun 27, 2025
141c984
Update justfile integration tests
Jun 27, 2025
73a9685
Fix clippy formatting
Jun 27, 2025
210e819
Update unit tests - reading sql files at compile time instead of run …
Jun 30, 2025
619722f
cargo fmt
Jun 30, 2025
20dce29
Update .pre-commit-config.yaml te check sqlite .sql files
Jun 30, 2025
18ca4c2
cargo clippy
Jun 30, 2025
9e70081
Update precommit config
Jun 30, 2025
635cc4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 30, 2025
91676a0
Update precommit config
Jun 30, 2025
3b69cca
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jun 30, 2025
c829c6c
Update cors_test.rs - Try to see if the test will pass without mbtiles
Jul 3, 2025
63a2dac
Update metadata.rs, validation.rs Added temp mbtiles helper functions
Jul 3, 2025
354dc70
Update summary.rs unit tests
Jul 3, 2025
259296d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 3, 2025
975e7cd
Update unit tests
Jul 7, 2025
ef5c08c
Update cors_test.rs
Jul 7, 2025
d14d312
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jul 7, 2025
c2ae072
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 7, 2025
9146167
Merge branch 'main' into generate-mbtiles-on-the-fly
nyurik Jul 7, 2025
26777f5
Update cors_tests.rs
Jul 7, 2025
675bc44
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jul 7, 2025
eeb9ee6
Update cors_test.rs
Jul 7, 2025
b198fa8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 7, 2025
7721520
Update cors_test.rs
Jul 7, 2025
8165e11
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jul 7, 2025
c6cbfdb
update lib.rs
Jul 7, 2025
a1d1311
update cors_test.rs
Jul 7, 2025
18c04f8
Merge branch 'maplibre:main' into generate-mbtiles-on-the-fly
sdf-jkl Jul 14, 2025
4f551d0
Update file_config.rs
Jul 14, 2025
10cce2d
Clippy fix file_config.rs
Jul 14, 2025
c3f4c2a
Update Cargo.toml
Jul 14, 2025
7ad1db8
Update mb_server_test.rs
Jul 14, 2025
8b87262
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 14, 2025
d5546fb
Cargo fmt mb_server_test.rs
Jul 14, 2025
a27ec4b
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
Jul 14, 2025
7d9d63d
Clippy fix
Jul 14, 2025
ffea3d8
Merge branch 'main' into generate-mbtiles-on-the-fly
sdf-jkl Jul 16, 2025
2e66b49
Merge branch 'main' into generate-mbtiles-on-the-fly
nyurik Jul 27, 2025
55fb2f1
Merge branch 'main' into generate-mbtiles-on-the-fly
sdf-jkl Jul 31, 2025
834ccf0
Update test outputs
Aug 1, 2025
ed008ba
Update test file
Aug 1, 2025
0200836
Update copy_bindiff_diff.txt
sdf-jkl Aug 1, 2025
24e6d42
Update copy_bindiff_diff.txt
sdf-jkl Aug 1, 2025
08986b9
Update copy_bindiff_diff.txt
sdf-jkl Aug 1, 2025
a0b2bb5
Merge branch 'main' into generate-mbtiles-on-the-fly
CommanderStorm Aug 1, 2025
c6af220
Merge branch 'main' into generate-mbtiles-on-the-fly
CommanderStorm Aug 9, 2025
65d3ddf
run just fmt && just fmt-toml
CommanderStorm Aug 9, 2025
40e0205
Merge branch 'main' of https://github.com/sdf-jkl/martin into generat…
sdf-jkl Sep 26, 2025
d02b857
Fix merge diff marker
sdf-jkl Sep 26, 2025
491bde9
Merge branch 'main' into generate-mbtiles-on-the-fly
sdf-jkl Sep 26, 2025
48d8f41
cargo clippy fix
sdf-jkl Sep 26, 2025
c91b2ae
Merge branch 'main' into generate-mbtiles-on-the-fly
CommanderStorm Sep 26, 2025
c4b10f2
UTF-8 BOM to UTF-8
sdf-jkl Sep 27, 2025
569ade3
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
sdf-jkl Sep 27, 2025
433cbf8
enable printing of nonprinting chars
CommanderStorm Sep 27, 2025
23f075a
fix line ending?
sdf-jkl Sep 28, 2025
744789b
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
sdf-jkl Sep 28, 2025
ffcc9e0
add prepare-fixtures recipe to ci-test
sdf-jkl Oct 1, 2025
3e87844
Merge branch 'main' into generate-mbtiles-on-the-fly
sdf-jkl Oct 1, 2025
ceea03b
fix: add mbtiles generation tothe CI
sdf-jkl Oct 1, 2025
853e53c
Merge branch 'generate-mbtiles-on-the-fly' of https://github.com/sdf-…
sdf-jkl Oct 1, 2025
01e4030
move prepare-fixtures into test.sh
sdf-jkl Oct 2, 2025
f33bc77
update test.sh
sdf-jkl Oct 2, 2025
8aca87f
install sqlite3 and slqdiff on Win in CI
sdf-jkl Oct 3, 2025
4797dc4
Merge branch 'main' into generate-mbtiles-on-the-fly
sdf-jkl Oct 3, 2025
2f1916c
Apply suggestions from code review
CommanderStorm Oct 3, 2025
bdcaee5
make sure that the generated mbtiles are not in git
CommanderStorm Oct 5, 2025
050ef46
update the testcase to use `temp_named_mbtiles`
CommanderStorm Oct 5, 2025
eb9bcdc
adapt the parser to handle file scheme urls properly
CommanderStorm Oct 5, 2025
f5882ec
fix clippy
CommanderStorm Oct 5, 2025
76f69c8
Merge branch 'main' into generate-mbtiles-on-the-fly
CommanderStorm Oct 5, 2025
a4776d1
fix just check
CommanderStorm Oct 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tests/mbtiles_temp_files/
tests/output/
tmp/
tsconfig.tsbuildinfo
*.mbtiles

####
#### Above content must match .gitignore ####
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ jobs:
- name: Set up gdal-bin and sqlite3-tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y gdal-bin sqlite3-tools

- name: Install sqlite3 and sqldiff on Windows
if: matrix.os == 'windows-latest'
run: choco install sqlite --yes
shell: powershell
- name: Install and run Postgis (Windows)
if: matrix.os == 'windows-latest'
uses: nyurik/action-setup-postgis@5183a5e26ade31809faed263cd4d638e144fe186 # v2.2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tests/mbtiles_temp_files/
tests/output/
tmp/
tsconfig.tsbuildinfo
*.mbtiles

####
#### Above content must match .dockerignore ####
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,23 @@ repos:
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.4.2
hooks:
# 1. Postgres dialect for general .sql files, excluding sqlite dirs
- id: sqlfluff-fix
# AL07: Avoid table aliases in from clauses and join conditions <- we sometimes do this for long names
# LT05: Line is too long <- not useful. mostly triggers for comments
# LT12: Files must end with a single trailing newline <- already done by trailing-whitespace
# If you update this rule, please also update the rules in justfile, the fmt-sql recipe
args: [ --dialect=postgres, "--exclude-rules=AL07,LT05,LT12" ]
files: \.sql$
exclude: ^tests/fixtures/(mbtiles|files)/.*\.sql$

# 2. SQLite dialect for .sql files in specific directories
- id: sqlfluff-fix
# LT01: Layout spacing adds space between x and 'blob' breaking the blobs
args: [--dialect=sqlite, "--exclude-rules=LT01,LT05"]
files: ^tests/fixtures/(mbtiles|files)/.*\.sql$

# TODO: Add NPM hooks for formatting and linting
# NPM hooks for JavaScript/TypeScript formatting and linting
- repo: https://github.com/biomejs/pre-commit
rev: "v2.2.4" # Use the sha / tag you want to point at
Expand Down
2 changes: 1 addition & 1 deletion docs/src/mbtiles-copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This command can also be used to generate files of different [supported schema](

```bash
mbtiles copy normalized.mbtiles dst.mbtiles \
--dst-mbttype flat-with-hash
--dst-type flat-with-hash
```

## `mbtiles copy --diff-with-file`
Expand Down
5 changes: 5 additions & 0 deletions docs/src/mbtiles-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ number of tiles per zoom level, the size of the smallest and largest tiles, and
level. The command will also print the bounding box of the covered area per zoom level.

```bash
# Create a sample .mbtiles file in some dir
sqlite3 target/world_cities.mbtiles < tests/fixtures/mbtiles/world_cities.sql
# Get mbtiles summary
mbtiles summary target/world_cities.mbtiles

MBTiles file summary for tests/fixtures/mbtiles/world_cities.mbtiles
Schema: flat
File size: 48.00KiB
Expand Down
59 changes: 4 additions & 55 deletions docs/src/mbtiles-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,27 @@ The `mbtiles` tool builds on top of the original [MBTiles specification](https:/
Flat schema is the closest to the original MBTiles specification. It stores all tiles in a single table. This schema is the most efficient when the tileset contains no duplicate tiles.

```sql, ignore
CREATE TABLE tiles (
zoom_level INTEGER,
tile_column INTEGER,
tile_row INTEGER,
tile_data BLOB);

CREATE UNIQUE INDEX tile_index on tiles (
zoom_level, tile_column, tile_row);
{{#include ../../mbtiles/sql/init-flat.sql}}
```

## flat-with-hash

Similar to the `flat` schema, but also includes a `tile_hash` column that contains a hash value of the `tile_data` column. Use this schema when the tileset has no duplicate tiles, but you still want to be able to validate the content of each tile individually.

```sql, ignore
CREATE TABLE tiles_with_hash (
zoom_level INTEGER NOT NULL,
tile_column INTEGER NOT NULL,
tile_row INTEGER NOT NULL,
tile_data BLOB,
tile_hash TEXT);

CREATE UNIQUE INDEX tiles_with_hash_index on tiles_with_hash (
zoom_level, tile_column, tile_row);

CREATE VIEW tiles AS
SELECT zoom_level, tile_column, tile_row, tile_data
FROM tiles_with_hash;
{{#include ../../mbtiles/sql/init-flat-with-hash.sql}}
```

## normalized

Normalized schema is the most efficient when the tileset contains duplicate tiles. It stores all tile blobs in the `images` table, and stores the tile Z,X,Y coordinates in a `map` table. The `map` table contains a `tile_id` column that is a foreign key to the `images` table. The `tile_id` column is a hash of the `tile_data` column, making it possible to both validate each individual tile like in the `flat-with-hash` schema, and also to optimize storage by storing each unique tile only once.

```sql, ignore
CREATE TABLE map (
zoom_level INTEGER,
tile_column INTEGER,
tile_row INTEGER,
tile_id TEXT);

CREATE TABLE images (
tile_id TEXT,
tile_data BLOB);

CREATE UNIQUE INDEX map_index ON map (
zoom_level, tile_column, tile_row);
CREATE UNIQUE INDEX images_id ON images (
tile_id);

CREATE VIEW tiles AS
SELECT
map.zoom_level AS zoom_level,
map.tile_column AS tile_column,
map.tile_row AS tile_row,
images.tile_data AS tile_data
FROM
map JOIN images
ON images.tile_id = map.tile_id;
{{#include ../../mbtiles/sql/init-normalized.sql}}
```

Optionally, `.mbtiles` files with `normalized` schema can include a `tiles_with_hash` view. All `normalized` files created by the `mbtiles` tool will contain this view.

```sql, ignore
CREATE VIEW tiles_with_hash AS
SELECT
map.zoom_level AS zoom_level,
map.tile_column AS tile_column,
map.tile_row AS tile_row,
images.tile_data AS tile_data,
images.tile_id AS tile_hash
FROM
map JOIN images
ON map.tile_id = images.tile_id;
{{#include ../../mbtiles/sql/init-normalized.sql:26:}}
```
8 changes: 7 additions & 1 deletion docs/src/quick-start-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ mkdir martin
cd martin

# Download some sample data
curl -L -O https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.mbtiles
curl -L -O https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.sql

# Check if sqlite is installed
sqlite3 --version

# Initialize a database
sqlite3 world_cities.mbtiles < world_cities.sql

# Download the latest version of Martin binary, extract it, and make it executable
curl -L -O https://github.com/maplibre/martin/releases/latest/download/martin-x86_64-unknown-linux-gnu.tar.gz
Expand Down
7 changes: 5 additions & 2 deletions docs/src/quick-start-macos.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Quick start on macOS

1. Download some [demo tiles](https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.mbtiles).
1. Download some [demo tiles](https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.sql).

2. Download the latest version of Martin from
the [release page](https://github.com/maplibre/martin/releases/latest).
Expand All @@ -10,11 +10,14 @@

3. Extract content of both files and place them in a same directory.

4. Open the command prompt and navigate to the directory where `martin` and `world_cities.mbtiles` are located.
4. Open the command prompt and navigate to the directory where `martin` and `world_cities.sql` are located.

5. Run the following command to start Martin with the demo data:

```bash
# Initialize a database
sqlite3 world_cities.mbtiles < world_cities.sql

# Show Martin help screen
./martin --help

Expand Down
10 changes: 8 additions & 2 deletions docs/src/quick-start-windows.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
## Quick start on Windows

1. Download some [demo tiles](https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.mbtiles).
1. Download some [demo tiles](https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.sql).

2. Download the latest Windows version of Martin from
the [release page](https://github.com/maplibre/martin/releases): [martin-x86_64-pc-windows-msvc.zip](https://github.com/maplibre/martin/releases/latest/download/martin-x86_64-pc-windows-msvc.zip)

3. Extract content of both files and place them in a same directory.

4. Open the command prompt and navigate to the directory where `martin` and `world_cities.mbtiles` are located.
4. Open the command prompt and navigate to the directory where `martin` and `world_cities.sql` are located.

5. Run the following command to start Martin with the demo data:

```bash
# Check if sqlite is installed
sqlite3 --version

# Initialize a database
sqlite3 world_cities.mbtiles < world_cities.sql

# Show Martin help screen
martin --help

Expand Down
5 changes: 3 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ fmt-md:

# Reformat all SQL files using docker
fmt-sql:
docker run -it --rm -v $PWD:/sql sqlfluff/sqlfluff:latest fix --dialect=postgres --exclude-rules=AL07,LT05,LT12
docker run -it --rm -v $PWD:/sql sqlfluff/sqlfluff:latest fix --dialect=postgres --exclude-rules=AL07,LT05,LT12 --exclude '^tests/fixtures/(mbtiles|files)/.*\.sql$'
docker run -it --rm -v $PWD:/sql sqlfluff/sqlfluff:latest fix --dialect=sqlite --exclude-rules=LT01,LT05 --files '^tests/fixtures/(mbtiles|files)/.*\.sql$'

# Reformat all Cargo.toml files using cargo-sort
fmt-toml *args: (cargo-install 'cargo-sort')
Expand Down Expand Up @@ -328,7 +329,7 @@ test-int: clean-test install-sqlx
echo "** If this is expected, run 'just bless' to update expected output"
echo ""
echo "::group::Resulting diff (max 100 lines)"
diff --recursive --new-file --exclude='*.pbf' tests/output tests/expected | head -n 100
diff --recursive --new-file --exclude='*.pbf' tests/output tests/expected | head -n 100 | cat --show-nonprinting
echo "::endgroup::"
exit 1
else
Expand Down
70 changes: 60 additions & 10 deletions martin/src/config/args/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ fn is_url(s: &str, extension: &[&str]) -> bool {
}
}

/// Check if a string is a `file:` scheme URI with a specified extension.
///
/// This is used for `SQLite` connection strings like `file:name.mbtiles?mode=memory&cache=shared`
#[cfg(any(feature = "cog", feature = "mbtiles", feature = "pmtiles"))]
fn is_file_scheme_uri(s: &str, extensions: &[&str]) -> bool {
let Ok(url) = url::Url::parse(s) else {
return false;
};
if url.scheme() != "file" {
return false;
}
url.path()
.rsplit('.')
.next()
.is_some_and(|ext| extensions.contains(&ext))
}

#[cfg(any(feature = "cog", feature = "mbtiles", feature = "pmtiles"))]
pub fn parse_file_args<T: crate::config::file::ConfigExtras>(
cli_strings: &mut Arguments,
Expand All @@ -186,6 +203,9 @@ pub fn parse_file_args<T: crate::config::file::ConfigExtras>(
let path = PathBuf::from(s);
if allow_url && is_url(s, extensions) {
Take(path)
} else if is_file_scheme_uri(s, extensions) {
// Handle file: scheme URIs (SQLite connection strings) as valid paths
Take(path)
} else if path.is_dir() {
Share(path)
} else if path.is_file()
Expand Down Expand Up @@ -285,6 +305,33 @@ mod tests {
assert_eq!(config4.unwrap().0.srv.preferred_encoding, None);
}

#[cfg(any(feature = "cog", feature = "mbtiles", feature = "pmtiles"))]
#[test]
fn test_is_file_scheme_uri() {
// Valid file scheme URIs
assert!(is_file_scheme_uri("file:test.mbtiles", &["mbtiles"]));
assert!(is_file_scheme_uri(
"file:test.mbtiles?mode=memory&cache=shared",
&["mbtiles"]
));
assert!(is_file_scheme_uri(
"file:/path/to/test.mbtiles",
&["mbtiles"]
));
assert!(is_file_scheme_uri("file:data.pmtiles", &["pmtiles"]));
assert!(is_file_scheme_uri("file:image.tiff", &["tiff", "tif"]));

// Invalid cases
assert!(!is_file_scheme_uri(
"http://example.com/test.mbtiles",
&["mbtiles"]
));
assert!(!is_file_scheme_uri("test.mbtiles", &["mbtiles"]));
assert!(!is_file_scheme_uri("file:test.txt", &["mbtiles"]));
assert!(!is_file_scheme_uri("file:", &["mbtiles"]));
assert!(!is_file_scheme_uri("", &["mbtiles"]));
}

#[test]
fn cli_bad_arguments() {
for params in [
Expand Down Expand Up @@ -318,23 +365,26 @@ mod tests {
}

#[cfg(all(feature = "pmtiles", feature = "mbtiles", feature = "cog"))]
#[test]
fn cli_multiple_extensions() {
#[tokio::test]
async fn cli_multiple_extensions() {
use std::ffi::OsString;

let script = include_str!("../../../../tests/fixtures/mbtiles/json.sql");
let (_mbt, _conn, file) = mbtiles::temp_named_mbtiles("json.mbtiles", script).await;
let args = Args::parse_from([
"martin",
"../tests/fixtures/pmtiles/png.pmtiles",
"../tests/fixtures/mbtiles/json.mbtiles",
"../tests/fixtures/cog/rgba_u8_nodata.tiff",
"../tests/fixtures/cog/rgba_u8.tif",
OsString::from("martin"),
OsString::from("../tests/fixtures/pmtiles/png.pmtiles"),
file.as_os_str().to_owned(),
OsString::from("../tests/fixtures/cog/rgba_u8_nodata.tiff"),
OsString::from("../tests/fixtures/cog/rgba_u8.tif"),
]);

let env = FauxEnv::default();
let mut config = Config::default();
let err = args.merge_into_config(&mut config, &env);
assert!(err.is_ok());
args.merge_into_config(&mut config, &env).unwrap();
insta::assert_yaml_snapshot!(config, @r#"
pmtiles: "../tests/fixtures/pmtiles/png.pmtiles"
mbtiles: "../tests/fixtures/mbtiles/json.mbtiles"
mbtiles: "file:json.mbtiles?mode=memory&cache=shared"
cog:
- "../tests/fixtures/cog/rgba_u8_nodata.tiff"
- "../tests/fixtures/cog/rgba_u8.tif"
Expand Down
25 changes: 17 additions & 8 deletions martin/src/config/file/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use martin_core::tiles::BoxedSource;
use serde::{Deserialize, Serialize};
use url::Url;

use crate::config::file::ConfigFileError::{
InvalidFilePath, InvalidSourceFilePath, InvalidSourceUrl, IoError,
};
use crate::config::file::ConfigFileError::{InvalidFilePath, InvalidSourceUrl, IoError};

use crate::{MartinError, MartinResult};

pub type ConfigFileResult<T> = Result<T, ConfigFileError>;
Expand Down Expand Up @@ -244,10 +243,24 @@ impl FileConfigSrc {

pub fn abs_path(&self) -> ConfigFileResult<PathBuf> {
let path = self.get_path();

if is_sqlite_memory_uri(path) {
// Skip canonicalization for in-memory DB URIs
return Ok(path.clone());
}

path.canonicalize().map_err(|e| IoError(e, path.clone()))
}
}

fn is_sqlite_memory_uri(path: &Path) -> bool {
if let Some(s) = path.to_str() {
s.starts_with("file:") && s.contains("mode=memory") && s.contains("cache=shared")
} else {
false
}
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct FileConfigSource {
pub path: PathBuf,
Expand Down Expand Up @@ -289,11 +302,7 @@ async fn resolve_int<T: SourceConfigExtras>(
} else {
let can = source.abs_path()?;
if !can.is_file() {
// todo: maybe warn instead?
return Err(MartinError::ConfigFileError(InvalidSourceFilePath(
id.to_string(),
can,
)));
log::warn!("The file: {} does not exist", can.display());
}

let dup = !files.insert(can.clone());
Expand Down
Loading
Loading