Closed SamStudio8 closed 1 year ago
Space characters in the home path
(sorry for closing I was too depressed 😆)
😹 I should have perhaps added that the context behind this is that WSL creates home dirs somewhere impractical for the uninitiated user. We encountered this problem when trying to set a more sensible NXF_HOME for our friends on WSL whose IT departments have carelessly provisioned their usernames with spaces in them. As much as spaces in a file path makes me feel queasy, it would be great to patch this to better support WSL users.
Anyhow, thanks for the excellent issue report 💪
Bug report
Expected behavior
NXF_HOME
can contain a space character andnextflow
will run without error.Actual behavior
Steps to reproduce the problem
Program output
Environment
Repros on Mac
and Ubuntu:
Additional context
When Nextflow is run for the first time, it attempts to generate a file containing the full Java command required to launch Nextflow with its options and the classpath for dependencies installed by Capsule. This is achieved by running the capsule and capturing the classpath information and writing it to the
LAUNCH_FILE
path.If
NXF_HOME
has spaces, so too will the generated classpath. The result of the process substitution used to collect the options and classpath by calling JAVA_CMD with JAVA_OPTS on the NXF_JAR is word split into thecli
array; breaking spaced components into separate elements. The Javacmd_base
is found with a regex oncli
, and everything else ends up incmd_tail
(still split by words). Thecmd_tail
is eventually appended to thelauncher
array.The
launcher
array is used bylaunch_nextflow
to generate thecmdline
string that will beexec
'd to actually run Nextflow for the first time. Due to previous problems with bash double quotes leading to "no such variable" errors, thelaunch_nextflow
function strips double quotations from elements oflauncher
, breaking the escaping of classpath elements with spaces when they are concatenated into thecmdline
string. This leads to-classpath
containing the argument_nextflow
and causing theClassNotFoundException
.On the second and subsequent invocations of Nextflow, the
launcher
array is instead populated by the contents of the previously generated LAUNCH_FILE (if it exists). The crucial difference in this case is that when the contents of the LAUNCH_FILE are read into thelauncher
array, the quoted elements are not broken on words. The surrounding quotes of each element are still removed bylaunch_nextflow
, but this does not matter because both the addition of the element tocmdline
and the call toexec
are correctly quoted later.Additionally, the superfluous directories are created when
mkdir
is called on the unquoted result ofdirname
to set up theJAVA_KEY
dir.Patch for inspiration
As a means to expedite a fix, the following patch offers some inspiration to fix the above behaviour by:
JAVA_KEY
to prevent the creation of unnecessary directoriescmd_tail
into an array of elements that respects quoted strings, allowing Nextflow to run first time if NXF_HOME contains spacesprintf
's%q
conversion operator to appropriately escape items inlauncher
for shell input when writing to LAUNCH_FILE, rather than relying on escaping with quotationsIt is worth noting that although the
%q
conversion operator appears to be well supported, it is not portable according to POSIX. In practice, I have not found this to be a problem, but I don't like it. Hopefully someone with more sh-fu than me has a better idea.