n2a icon indicating copy to clipboard operation
n2a copied to clipboard

Consider removing absolute paths from `model.sh`

Open chimaerase opened this issue 1 year ago • 4 comments

As part of testing exported models, I realized that model.sh files generated during export contain several absolute paths to the export directory. Ideally from my perspective, .sh files should avoid including absolute paths, e.g. so the entire export directory can be arbitrarily relocated (less any external path dependencies in the model).

A simplified export script might be something like the following, where the working directory would be controlled by the user / client code:

#!/bin/bash
./model.bin >> out 2>> err
if [ $? -eq 0 ]; then
  echo success > finished
else
  echo failure > finished
fi

chimaerase avatar Jan 18 '24 22:01 chimaerase

The original motivation for the absolute paths was to make it easier to launch a detached process from Java. I'll check if there is a good way to do this without relying on the shell script to change directories.

frothga avatar Jan 19 '24 16:01 frothga

Turns out that for remote jobs, it gets more complicated to handle paths when they're relative. Since this is not a high-priority issue, I am closing this as "won't fix".

frothga avatar Jan 19 '24 21:01 frothga

Thank you for taking a look! I agree this isn't a priority since the solution is complicated.

chimaerase avatar Jan 20 '24 01:01 chimaerase

While looking at this issue, a thought came to me on how to deal with the remote path issue. I'm reopening this, just to keep it on the TODO list.

The main issue with relative remote paths is how to transmit them through SSH. The current procedure is to convert them to absolute paths, then quote if needed. The part about converting to absolute path could be removed, as there isn't really a good way to do this. The current method is just a hack that is rarely actually used, and doesn't really work when it is used. Instead, paths will be transmitted exactly as is.

The remaining issue is that a relative path to an executable will generally fail. It is usually an immediate reference to an executable in the current working directory (CWD), but "." isn't necessarily in the search path. Rather than requiring the user to configure this, we should prepend a dot to the path. However, we shouldn't do that with every single relative path. The trick here is to extend Host.quote() to take a flag indicating whether to treat the path as an executable.

frothga avatar Jan 22 '24 14:01 frothga