2

This works:

TMPDIR="/tmp/___"
export TMPDIR
mkdir -p "$TMPDIR"
script="$TMPDIR"/myscript
cat <<'EOF' > "$script"                                                                       
#!/usr/bin/Rscript --vanilla --slave                                                          
EOF

chmod 755 "$script" ls -l "$script" "$script" ls -l "$script"

This removes $script and files in /tmp DO NOT RUN THIS IF YOU HAVE IMPORTANT STUFF IN /tmp:

TMPDIR="/tmp/   "
export TMPDIR
mkdir -p "$TMPDIR"
script="$TMPDIR"/myscript
cat <<'EOF' > "$script"                                                                       
#!/usr/bin/Rscript --vanilla --slave                                                          
EOF

chmod 755 "$script" ls -l "$script" "$script" ls -l "$script"

The difference between these is only $TMPDIR contains spaces.

What is the reason for this difference in behaviour?

$ Rscript --version
R scripting front-end version 4.1.2 (2021-11-01)
$ cat /etc/issue.net 
Ubuntu 22.04.1 LTS

It looks more and more like a bug. If you compile R from source and set TMPDIR=" ":

:
make[3]: Entering directory '/tmp/R-devel/src/library/profile'
building system startup profile
make[3]: Leaving directory '/tmp/R-devel/src/library/profile'
make[3]: Entering directory '/tmp/R-devel/src/library/translations'
building package 'translations'
make[4]: Entering directory '/tmp/R-devel/src/library/translations'
make[4]: Leaving directory '/tmp/R-devel/src/library/translations'
make[3]: Leaving directory '/tmp/R-devel/src/library/translations'
make[3]: Entering directory '/tmp/R-devel/src/library/base'
building package 'base'
make[4]: Entering directory '/tmp/R-devel/src/library/base'
/bin/bash: line 9:  /R3273656: No such file or directory
/bin/bash: line 12:  /R23273656: No such file or directory
cmp:  /R23273656: No such file or directory
mv: cannot stat ' /R23273656': No such file or directory
make[4]: *** [../../../share/make/basepkg.mk:65: mkRbase] Error 1
make[4]: Leaving directory '/tmp/R-devel/src/library/base'
make[3]: *** [Makefile:31: all] Error 2
make[3]: Leaving directory '/tmp/R-devel/src/library/base'
make[2]: *** [Makefile:37: R] Error 1
make[2]: Leaving directory '/tmp/R-devel/src/library'
make[1]: *** [Makefile:28: R] Error 1
make[1]: Leaving directory '/tmp/R-devel/src'
make: *** [Makefile:62: R] Error 1

Also changing TMPDIR in sysutils.c:1893 to DUMMY makes the issue go away.

Ole Tange
  • 35,514
  • Can you please edit and give a bit of context? What OS is this on? Are you saying that running the script deletes all files in /tmp or some files? Only files? No directories? It looks like the only difference between the two cases is the value of TMPDIR and if it has trailing spaces, is that right or is there some other difference as well? It really helps if you point out the differences instead of making us try to find them since it is easy for us to miss something. – terdon Jan 25 '23 at 22:27
  • OK, this is just weird. I can indeed reproduce it on my Arch and it looks like it tries to delete everything in /tmp. What's worse, I get the exact same result if I simply run touch "$TMPDIR"/myscript; Rscript "$TMPDIR"/myscript. So giving Rscript an empty R script to run causes it to attempt to delete all files. – terdon Jan 25 '23 at 22:35
  • @terdon It is not the empty script. It is setting TMPDIR to a dir with spaces, that triggers the issue. – Ole Tange Jan 26 '23 at 23:24
  • Yes, of course, I mean it is enough to just run Rscript, no need for the Rscript shebang line, just run Rscript whateverFile and we get the same issue. It really feels like a bug in Rscript. – terdon Jan 27 '23 at 00:37

0 Answers0