osmcode / osmium-tool

Command line tool for working with OpenStreetMap data based on the Osmium library.
https://osmcode.org/osmium-tool/
GNU General Public License v3.0
483 stars 104 forks source link

Windows: absolute path for polygon #259

Closed IldarKhayrutdinov closed 1 year ago

IldarKhayrutdinov commented 1 year ago

On Windows I get an error when using absolute path for polygon:

C:\temp>osmium extract test.osm -p C:\temp\subdir\regions.geojson -o out.osm
Could not open file './C:\temp\subdir\regions.geojson'.

Relative path works fine:

C:\temp>osmium extract test.osm -p subdir\regions.geojson -o out.osm
[======================================================================] 100%

This PR is fixes for this bug.

I hope it's the correct to use <experimental/filesystem>.

joto commented 1 year ago

This is a C++11 library so I don't want to use anything not available there officially. And I don't want to get into the problem of having std::experimental::filesystem vs. std::filesystem. There must have been a way to do this check in Windows before we got std::filesystem?

IldarKhayrutdinov commented 1 year ago

@joto Sure, I'll try now. Done.

IldarKhayrutdinov commented 1 year ago

@joto I'll later implement without includes, as https://github.com/dotnet/runtime/blob/174e04336e4a073416cb0baebb2be72728b9d64b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs#L271

UPD Done

IldarKhayrutdinov commented 1 year ago

@joto I don't understand why the build fails, did you looked at the latest revision?

IldarKhayrutdinov commented 1 year ago

Thank you for your patience :)

Yes, I have tested on Windows:

Absolute path:

c:\temp>osmium extract test.osm -p C:\temp\subdir\regions.geojson -o out.osm
[======================================================================] 100%

Relative paths:

c:\temp>osmium extract test.osm -p subdir\regions.geojson -o out.osm -O
[======================================================================] 100%

c:\temp>osmium extract test.osm -p ./subdir\regions.geojson -o out.osm -O
[======================================================================] 100%

c:\temp>osmium extract test.osm -p .\subdir\regions.geojson -o out.osm -O
[======================================================================] 100%

c:\temp>osmium extract test.osm -p ..\temp/subdir\regions.geojson -o out.osm -O
[======================================================================] 100%

These cases should be used with caution with the config file, there may be confusion:

A relative path from the current directory of the C: drive:

c:\temp>osmium extract test.osm -p C:subdir\regions.geojson -o out.osm -O
[======================================================================] 100%

A relative path from the root of the current drive:

c:\temp>osmium extract test.osm -p /temp/subdir\regions.geojson -o out.osm -O
[======================================================================] 100%

https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#traditional-dos-paths

joto commented 1 year ago

Thank you @IldarKhayrutdinov !