Bug #1580
ctools cannot read filename using "~" referring to home directory
Status: | Closed | Start date: | 11/19/2015 | |
---|---|---|---|---|
Priority: | Low | Due date: | ||
Assigned To: | Knödlseder Jürgen | % Done: | 100% | |
Category: | - | |||
Target version: | - | |||
Duration: |
Description
I am not sure if this is more a feature than a bug.
Running a ctool on my mac and trying to load a file on my Desktop in the following way results in an error:
$ ctselect Input event list or observation definition file [events.fits] ~/Desktop/obs.xml *** ERROR in GXml::load(std::string&): Unable to open file "~/Desktop/obs.xml" *** ERROR encounterted in the execution of ctselect. Run aborted ...
The file is however present. The following call works:
$ ctselect Input event list or observation definition file [~/Desktop/obs.xml] /Users/mimayer/Desktop/obs.xml
Tracing the problem, I wind up in
gammalib::expand_env
. The function does not interpret “~” in a string (e.g. as $HOME).
Recurrence
No recurrence.
History
#1 Updated by Knödlseder Jürgen about 9 years ago
Interesting, I thought that the decoding of the ~
symbol happens on the system level, but this seems not to be the case.
Note, however, that ~mike
means /home/mike
(or /Users/mike
on Mac OS X).
I agree that both capabilities should be added to gammalib::expand_env
.
#2 Updated by Mayer Michael about 9 years ago
I just verified this does not work on Scientific Linux, too.
I am not sure how the function gammailib::expand_env
works exactly. Is it an effort for you to implement this?
#3 Updated by Knödlseder Jürgen about 9 years ago
I can look into that. Is it an urgent issue?
#4 Updated by Knödlseder Jürgen about 9 years ago
- Assigned To set to Knödlseder Jürgen
#5 Updated by Mayer Michael about 9 years ago
This probably belongs to the gammalib
project after all.
I can look into that. Is it an urgent issue?
Thanks. No, not urgent at all simple workaround is to specify absolut paths. I just noted it and wanted it to be documented that we do not forget.
#6 Updated by Knödlseder Jürgen about 9 years ago
- Project changed from ctools to GammaLib
#7 Updated by Knödlseder Jürgen about 9 years ago
Here the logic how bash
treats the tilde: http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html
See the following link to learn how to access a users home directory: http://stackoverflow.com/questions/2910377/get-home-directory-in-linux-c
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
const char *homedir;
if ((homedir = getenv("HOME")) == NULL) {
homedir = getpwuid(getuid())->pw_dir;
}
Use getpwnam
to retrieve the pw
structure for an arbitrary user: http://linux.die.net/man/3/getpwnam#8 Updated by Knödlseder Jürgen about 9 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
I added the interpretation of ~, ~user, ~+ and ~- to the gammalib::expand_env() function.
Merged into devel
.