sagemath/sage

saving a tikzpicture to a local folder is now broken

seblabbe opened this issue · 9 comments

Now that temporary files are created in the /tmp folder (after #33797), the following is now broken in 9.7.beta1:

sage: from sage.misc.latex_standalone import Standalone
sage: s = Standalone('Hello World')
sage: s.pdf('a.pdf')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-3-61662d74848f> in <module>
----> 1 s.pdf('a.pdf')

~/GitBox/sage/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages/sage/misc/latex_standalone.py in pdf(self, filename, view, program)
    729         if filename:
    730             filename = os.path.abspath(filename)
--> 731             os.rename(temp_filename_pdf, filename)
    732             return filename
    733 

OSError: [Errno 18] Invalid cross-device link: '/tmp/tmpwfvogvku/tikz_15rndaqh.pdf' -> '/home/.../a.pdf'

This went unnoticed because everywhere in the doctests the files are created in the temporary folder.

Component: graphics

Author: Sébastien Labbé

Branch/Commit: c4e8178

Reviewer: Michael Orlitzky

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

comment:1

A solution seems to be to use shutil.move instead.

New commits:

c4e817833944: using shutil.move instead of os.rename

Author: Sébastien Labbé

Commit: c4e8178

Description changed:

--- 
+++ 
@@ -1,4 +1,4 @@
-Now that temporary files are created in the `/tmp` folder (after #33797), the following is now broken:
+Now that temporary files are created in the `/tmp` folder (after #33797), the following is now broken in 9.7.beta1:
 
 ```
 sage: from sage.misc.latex_standalone import Standalone

Reviewer: Michael Orlitzky

comment:4

I think this would have been broken already when saving to a filesystem other than the one that SAGE_TMP lives on. The fix looks correct, thanks.

Changed branch from u/slabbe/33944 to c4e8178