Skip to content

Commit

Permalink
increase robustness of the method
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Mar 18, 2024
1 parent e0db1df commit d7e169a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/io/bioimage/modelrunner/apposed/appose/Mamba.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void updateIn( final String envName, final String... args ) throws IOExce
{
checkMambaInstalled();
if (!installed) throw new MambaInstallException("Micromamba is not installed");
final List< String > cmd = new ArrayList<>( Arrays.asList( "update", "-p", this.envsdir + File.separator + envName ) );
final List< String > cmd = new ArrayList<>( Arrays.asList( "update", "-p", checkExecutablePath(this.envsdir + File.separator + envName )) );
cmd.addAll( Arrays.asList( args ) );
if (!cmd.contains("--yes") && !cmd.contains("-y")) cmd.add("--yes");
runMamba( cmd.stream().toArray( String[]::new ) );
Expand Down Expand Up @@ -545,7 +545,7 @@ public void createWithYaml( final String envName, final String envYaml, final bo
if ( !isForceCreation && getEnvironmentNames().contains( envName ) )
throw new EnvironmentExistsException();
runMamba("env", "create", "--prefix",
envsdir + File.separator + envName, "-f", envYaml, "-y", "-vv" );
checkExecutablePath(envsdir + File.separator + envName), "-f", envYaml, "-y", "-vv" );
}

/**
Expand Down Expand Up @@ -593,7 +593,7 @@ public void create( final String envName, final boolean isForceCreation ) throws
if (!installed) throw new MambaInstallException("Micromamba is not installed");
if ( !isForceCreation && getEnvironmentNames().contains( envName ) )
throw new EnvironmentExistsException();
runMamba( "create", "-y", "-p", envsdir + File.separator + envName );
runMamba( "create", "-y", "-p", checkExecutablePath(envsdir + File.separator + envName) );
}

/**
Expand Down Expand Up @@ -647,7 +647,7 @@ public void create( final String envName, final boolean isForceCreation, final S
if (!installed) throw new MambaInstallException("Micromamba is not installed");
if ( !isForceCreation && getEnvironmentNames().contains( envName ) )
throw new EnvironmentExistsException();
final List< String > cmd = new ArrayList<>( Arrays.asList( "create", "-p", envsdir + File.separator + envName ) );
final List< String > cmd = new ArrayList<>( Arrays.asList( "create", "-p", checkExecutablePath(envsdir + File.separator + envName) ) );
cmd.addAll( Arrays.asList( args ) );
if (!cmd.contains("--yes") && !cmd.contains("-y")) cmd.add("--yes");
runMamba( cmd.stream().toArray( String[]::new ) );
Expand Down Expand Up @@ -821,7 +821,7 @@ public void installIn( final String envName, List<String> channels, List<String>
checkMambaInstalled();
if (!installed) throw new MambaInstallException("Micromamba is not installed");
Objects.requireNonNull(envName, "The name of the environment of interest needs to be provided.");
final List< String > cmd = new ArrayList<>( Arrays.asList( "install", "-y", "-p", this.envsdir + File.separator + envName ) );
final List< String > cmd = new ArrayList<>( Arrays.asList( "install", "-y", "-p", checkExecutablePath(this.envsdir + File.separator + envName )) );
if (channels == null) channels = new ArrayList<String>();
for (String chan : channels) { cmd.add("-c"); cmd.add(chan);}
if (packages == null) packages = new ArrayList<String>();
Expand Down Expand Up @@ -850,7 +850,7 @@ public void installIn( final String envName, final String... args ) throws IOExc
{
checkMambaInstalled();
if (!installed) throw new MambaInstallException("Micromamba is not installed");
final List< String > cmd = new ArrayList<>( Arrays.asList( "install", "-p", this.envsdir + File.separator + envName ) );
final List< String > cmd = new ArrayList<>( Arrays.asList( "install", "-p", checkExecutablePath(this.envsdir + File.separator + envName )) );
cmd.addAll( Arrays.asList( args ) );
if (!cmd.contains("--yes") && !cmd.contains("-y")) cmd.add("--yes");
runMamba( cmd.stream().toArray( String[]::new ) );
Expand Down Expand Up @@ -1573,6 +1573,8 @@ public boolean checkEnvFromYamlExists(String envYaml) throws MambaInstallExcepti
private static String checkExecutablePath(String path) {
String[] specialChars = new String[] {" "};
for (String schar : specialChars) {
if (path.startsWith("\"") && path.endsWith("\""))
continue;
if (path.contains(schar) && PlatformDetection.isWindows()) {
return "\"" + path + "\"";
}
Expand Down

0 comments on commit d7e169a

Please sign in to comment.