Hi Igor,<br><br>Thanks for the patches, they're much appreciated. Both of these issues have been around for a while so it will be great to see them fixed.<br><br>I haven't applied the patches yet, but will try to get to it over the next few days if nobody else beats me to it.<br>
<br>Cheers,<br>Brett<br><br><div class="gmail_quote">On Wed, Feb 16, 2011 at 4:25 AM, Igor Podolskiy <span dir="ltr"><<a href="mailto:igor.podolskiy@vwi-stuttgart.de">igor.podolskiy@vwi-stuttgart.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi,<br>
<br>
one of my students and I managed to discover different issues with the Osmosis launch scripts in the $OSMOSIS/bin directory, both on Windows and Unix-like systems.<br>
<br>
The shell script (osmosis) will fail or even worse, silently pass incorrect parameters to the Java process if any of the parameter values contain spaces. Consider the following command entered in an interactive shell:<br>
<br>
osmosis --read-apidb database="osm" user="os m" password="os m" --write-null<br>
<br>
This will fail with the "Only one default (un-named) argument can exist per task." message. Changing the quoting on the original command line doesn't help.<br>
<br>
The problem is with the way osmosis shell script executes the java runtime. The relevant lines of the script read like this:<br>
<br>
EXEC="$JAVACMD ... $MAINCLASS $OSMOSIS_OPTIONS $@"<br>
exec $EXEC<br>
<br>
While interpolating the $@ in this expression, the shell discards all original quoting. The solution I've found for this is doing the following:<br>
<br>
EXEC="$JAVACMD ... $MAINCLASS $OSMOSIS_OPTIONS"<br>
exec $EXEC "$@"<br>
<br>
Apparently, the exact sequence "$@" instructs the shell to preserve original quoting in the arguments, while "foo $@" does not. It doesn't make any sense to me, either, but it's probably some compatibility burden from decades ago. Anyway, the attached patch osmosis-shell-quoting.patch makes the necessary change (tested on Ubuntu 9.10 with bash 4.0.33 and /bin/sh which is linked to dash 0.5.5.1 here).<br>
<br>
The Windows batch script gets the quoting right, but fails if Osmosis is installed on a drive different from the current working directory of the user. This is somewhat tricky, so I'll try to explain it step by step.<br>
<br>
Assume that Osmosis is installed in c:\osmosis, PATH includes c:\osmosis\bin, and the current working directory is d:\data. User types:<br>
<br>
d:\data> osmosis --read-xml dump.osm --write-null<br>
<br>
The osmosis.bat script does the following:<br>
<br>
set SAVEDIR=%CD% # SAVEDIR == d:\data<br>
set MYAPP_HOME=%~dp0.. # MYAPP_HOME == c:\osmosis\bin\..<br>
cd %MYAPP_HOME% # expands to cd c:\osmosis\bin\.. <-- BUG!<br>
# %CD% == d:\data<br>
set MYAPP_HOME=%CD% # MYAPP_HOME == d:\data, which is clearly wrong.<br>
# everything fails hereafter as the classpath points to d:\data\lib etc.<br>
<br>
The bug is that the current working directory (%CD%) didn't change after cd %MYAPP_HOME% since the working directories are per-drive as they were in DOS 2.0 or so and we're on drive D: and did just change the CWD for drive C:.<br>
<br>
The solution is really simple: all this %SAVEDIR% theater for "getting the absolute path" isn't necessary at all, because %~dp0 already returns the absolute path ('d' magic letter gets the drive, 'p' gets the full path, as documented on TechNet), so<br>
<br>
set MYAPP_HOME=%dp~0<br>
<br>
is perfectly sufficient, AFAIK.<br>
<br>
The attached osmosis-batch-cwd.patch does the necessary change, tested on Windows 7 (32-bit).<br>
<br>
Both patches apply to current trunk. I'd also like to thank Markus Bernd Wagner from the University of Stuttgart for discovering the shell script issue. If anything is wrong with the patches, just say so, I'll try to fix it.<br>
<br>
Best regards<br><font color="#888888">
Igor<br>
</font><br>_______________________________________________<br>
osmosis-dev mailing list<br>
<a href="mailto:osmosis-dev@openstreetmap.org">osmosis-dev@openstreetmap.org</a><br>
<a href="http://lists.openstreetmap.org/listinfo/osmosis-dev" target="_blank">http://lists.openstreetmap.org/listinfo/osmosis-dev</a><br>
<br></blockquote></div><br>