sagemath/sage

lazy_import_cache.get_cache_file doesn't work well if DOT_SAGE doesn't end with a slash

jhpalmieri opened this issue · 4 comments

The function get_cache_file in sage/misc/lazy_import_cache.py uses this code:

return "%s%s-lazy_import_cache.pickle" % (
       os.environ['DOT_SAGE'], 
       os.path.realpath(os.path.join(os.environ['SAGE_ROOT'], 'devel', 'sage')).replace(os.sep, '_'))

Since this just appends to DOT_SAGE, it returns a file in a different directory depending on whether DOT_SAGE ends with a slash or not: if DOT_SAGE is /home/user/.sage/, then this gives

/home/user/.sage/_mangled_SAGE_ROOT_...

whereas if DOT_SAGE is /home/user/.sage, then it gives

/home/user/.sage_mangled_SAGE_ROOT_...

which is a file in the directory /home/user/, not in .sage/.

The attached patch uses os.path.join to combine the parts of the path correctly. (I also wonder if it would be a good idea to store the cache file in a different directory, say DOT_SAGE/cache/, so it's hidden more than it is currently?)

Component: misc

Author: John Palmieri

Reviewer: Jeroen Demeyer

Merged: sage-4.8.alpha3

Issue created by migration from https://trac.sagemath.org/ticket/11924

comment:2

I've given this "major" priority because any user who sets their DOT_SAGE to a string without a trailing slash ends up getting their home directory polluted with Sage lazy import cache files. For example, on skynet, I have

export DOT_SAGE="/home/palmieri/.sage_$HOSTNAME"

and I end up with many files in /home/palmieri: one for each host on which I build and Sage, one for each version of Sage. Fortunately the files start with a dot so they're hidden, but still, it's not a good situation.

(I can fix this for my situation by adding a trailing slash, but I shouldn't have to.)

Reviewer: Jeroen Demeyer

Merged: sage-4.8.alpha3