grass icon indicating copy to clipboard operation
grass copied to clipboard

lib: fixing slash to HOST_DIRSEP

Open neteler opened this issue 1 year ago • 10 comments

Changes hardcoded slash (/) in path to HOST_DIRSEP for portability.

Fixes #3296

neteler avatar Jun 16 '24 22:06 neteler

Failures are weird, and Windows has way more, many tests exited right away, as instead of taking 50min, tests took 11 min.

echoix avatar Jun 17 '24 08:06 echoix

This ends up with mixed / and \ which I believe was part of the original problem: ERROR: Unable to make mapset element .tmp\unknown (C:\Users\runneradmin\nc_spm_full_v2alpha2\__general_g_remove_test_g_remove_fv_az587_258_3624/.tmp\unknown. This particular forward slash originates from https://github.com/OSGeo/grass/blob/60f67276fbee985042f9fc571f824bb2c863ffbe/lib/gis/mapset_msc.c#L183

nilason avatar Jun 17 '24 08:06 nilason

In 6749496 I have changed more occurrences of '/' to HOST_DIRSEP. Hope I got it right, pls review.

The search I used was:

ag " '/'"

neteler avatar Jun 17 '24 14:06 neteler

Let us see the results of CI runners first.

There are a number of hardcoded cases with / for files in $GISBASE, e.g. etc/symbols, etc/proj etc. Perhaps it is not necessary to change every case now (locating $GISBASE with contents will have to have a somewhat different solution for FHS anyway).

nilason avatar Jun 17 '24 14:06 nilason

Failures like this in the log, still mixed...:

ERROR: Unable to make mapset element vector/random_points (C:\Users\runneradmin\nc_spm_full_v2alpha2\__vector_v_what_rast3_test.v.what.rast3_fv_az1783_710_4036\vector/random_points): No such file or directory

neteler avatar Jun 17 '24 17:06 neteler

I'm confused about the discussion here.

Changes hardcoded slash (/) in path to HOST_DIRSEP for portability.

Portability is not an issue. / is a perfectly fine directory separator on Windows (AltDirectorySeparatorChar).

This ends up with mixed / and \ which I believe was part of the original problem: ERROR: Unable to make mapset element...

Are you saying that the mixing causes the error, forward slash, or are we simply trying to fix the inconsistency in the error message?

wenzeslaus avatar Jun 19 '24 05:06 wenzeslaus

Mixing may not be good, especially when scripting comes into play.

hellik avatar Jun 19 '24 05:06 hellik

Mixing may not be good, especially when scripting comes into play.

We'd need to verify by manually doing a single fix and seeing if this one is fixed, but I think that it is only problematic from a Cygwin/msys2 point of there are both. But we need to see that the changes here remove some errors.

echoix avatar Jun 19 '24 06:06 echoix

Portability is not an issue. / is a perfectly fine directory separator on Windows (AltDirectorySeparatorChar).

That is unfortunately only valid for .NET API, perhaps https://superuser.com/a/176395 may throw some light into the issue at hand. I'm afraid that our code is full of hardcoded /: changing all that will be a huge effort, perhaps unnecessarily.

I'm not aware of current other issues than #3296 that reports this kind of problem, so it maybe a less invasive/ more immediate fix for g.tempfile to convert the tempfile path with G_convert_dirseps_to_host().

This problem with mixed use of characters originates from the fact that libgis make an effort to use HOST_DIRSEP, but pretty much everywhere else the hardcoded / is used.

nilason avatar Jun 19 '24 06:06 nilason

Apart from the cygpath tool, what other conversions does msys2 do? There's this docs https://www.msys2.org/docs/filesystem-paths/

They say that they convert automatically env vars, process arguments. Native tools would work with both if they don't process the path too much and forwards it the the system API, which is what Cygwin's POSIX API does (forwarding to the Windows API)

echoix avatar Jun 19 '24 08:06 echoix