使用带有自定义临时目录的install.packages [英] Using install.packages with custom temp dir
问题描述
我想安装一个软件包,该软件包的安全配置文件不能访问 / tmp
,但是具有自己的临时目录,例如 / tmp / jeroen
。但是,即使我尝试传递 TMPDIR
环境变量,它仍然会失败,因为它尝试使用 / tmp
。在一个使用 RAppArmor 和 unixtools (有关测试配置文件,请参见此处)
I would like to install a package with a security profile that does not have access to /tmp
, but has its own temporary directory, for example /tmp/jeroen
. However even though I try to pass the TMPDIR
environment variable, it still fails because it tries to use /tmp
. Below a toy example using RAppArmor and unixtools (see here for the test profile)
> library(RAppArmor)
> library(unixtools)
> dir.create("/tmp/jeroen")
> set.tempdir("/tmp/jeroen")
> setwd(tempdir());
> aa_change_profile("r-test")
Switching profiles...
> print(tempdir());
[1] "/tmp/jeroen"
> install.packages("plyr", lib="/tmp/jeroen", configure.vars="TMPDIR=/tmp/jeroen")
trying URL 'http://cran.rstudio.com/src/contrib/plyr_1.8.tar.gz'
Content type 'application/x-gzip' length 384462 bytes (375 Kb)
opened URL
==================================================
downloaded 375 Kb
Fatal error: cannot create 'R_TempDir'
The downloaded source packages are in
‘/tmp/jeroen/downloaded_packages’
查看 kern.log
文件(记录安全消息)时,发现问题是 R CMD安装
仍尝试使用 / tmp
,但被拒绝了:
When looking at the kern.log
file (which logs security messages), it turns out that the problem is that R CMD INSTALL
still tried to use /tmp
which was denied:
Jul 24 19:41:34 Jeroen-Antec kernel: [16270.696805] type=1400 audit(1374687694.097:599):
apparmor="DENIED" operation="mkdir" parent=5798 profile="r-test" name="/tmp/RtmpcUOJuQ/"
pid=5802 comm="R" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
有什么办法可以告诉 R CMD安装
使用 / tmp / jeroen
Is there any way I can tell R CMD INSTALL
to use /tmp/jeroen
instead?
推荐答案
@hadley在评论中给出了正确答案:为了确保 install.packages
使用自定义的临时目录,需要这样做
The correct answer was given by @hadley in the comments: in order to make sure install.packages
uses the custom temporary directory, one needs to do
Sys.setenv(TMPDIR="/tmp/jeroen")
除了:
configure.vars="TMPDIR=/tmp/jeroen"
通过这种方式提取和安装软件包都可以避免系统或用户默认的临时目录。
This way both the extraction and the installation of the package avoids the system or user default temporary directory.
这篇关于使用带有自定义临时目录的install.packages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!