Rstudio connect ERROR: moving to final location failed

Hi everyone,

we're currently in the process of build out our RStudio Connect instance at work and deployment goes well until it attempts to install the xml2 package.

[Connect] 2021/06/16 13:42:18.765221386 [1] "Command failed (1)\n\nFailed to run system command:\n\n\t'/usr/local/lib/R/bin/R' --vanilla CMD INSTALL --preclean '/opt/rstudio-connect/mnt/tmp/RtmpbG7MvM/packrat-install-6dc127ffc4a8/xml2' --library='/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4' --install-tests --no-docs --no-multiarch --no-demo \n\nThe command failed with output:\n* installing *source* package ‘xml2’ ...\n** package ‘xml2’ successfully unpacked and MD5 sums checked\n** using staged installation\nFound pkg-config cflags and libs!\nUsing PKG_CFLAGS=-I/usr/include/libxml2\nUsing PKG_LIBS=-lxml2\n** libs\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c connection.cpp -o connection.o\ngcc -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include
[Connect] /libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_doc.cpp -o xml2_doc.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_init.cpp -o xml2_init.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wd
[Connect] ate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_namespace.cpp -o xml2_namespace.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_node.cpp -o xml2_node.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_output.cpp -o xml2_output.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_schema.cpp -o xml2_schema.o\ng++ -std=gnu++11 -I\"/usr/local
[Connect] /lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_url.cpp -o xml2_url.o\ng++ -std=gnu++11 -I\"/usr/local/lib/R/include\" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_xpath.cpp -o xml2_xpath.o\ng++ -std=gnu++11 -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o xml2.so connection.o init.o xml2_doc.o xml2_init.o xml2_namespace.o xml2_node.o xml2_output.o xml2_schema.o xml2_url.o xml2_xpath.o -lxml2 -L/usr/local/lib/R/lib -lR\ninstalling to /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4/00LOCK-xml2/00new/xml2/libs\n** R\n** inst\n** tests\n** byte-compile and prepare package for lazy loading\n** help\n*** installing h
[Connect] elp indices\n** building package indices\n** installing vignettes\n** testing if installed package can be loaded from temporary location\n** checking absolute paths in shared objects and dynamic libraries\nmv: cannot move '/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4/00LOCK-xml2/00new/xml2' to '/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4/xml2': Permission denied\nERROR:   moving to final location failed"
[Connect] 2021/06/16 13:42:18.803014150 Error: Command failed (1)
[Connect] 2021/06/16 13:42:18.803017350 
[Connect] 2021/06/16 13:42:18.803047952 Failed to run system command:
[Connect] 2021/06/16 13:42:18.803048852 
[Connect] 2021/06/16 13:42:18.803054853 	'/usr/local/lib/R/bin/R' --vanilla CMD INSTALL --preclean '/opt/rstudio-connect/mnt/tmp/RtmpbG7MvM/packrat-install-6dc127ffc4a8/xml2' --library='/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4' --install-tests --no-docs --no-multiarch --no-demo 
[Connect] 2021/06/16 13:42:18.803060753 
[Connect] 2021/06/16 13:42:18.803067153 The command failed with output:
[Connect] 2021/06/16 13:42:18.803067753 * installing *source* package ‘xml2’ ...
[Connect] 2021/06/16 13:42:18.803074754 ** package ‘xml2’ successfully unpacked and MD5 sums checked
[Connect] 2021/06/16 13:42:18.803075554 ** using staged installation
[Connect] 2021/06/16 13:42:18.803084054 Found pkg-config cflags and libs!
[Connect] 2021/06/16 13:42:18.803084755 Using PKG_CFLAGS=-I/usr/include/libxml2
[Connect] 2021/06/16 13:42:18.803108156 Using PKG_LIBS=-lxml2
[Connect] 2021/06/16 13:42:18.803109156 ** libs
[Connect] 2021/06/16 13:42:18.803115657 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c connection.cpp -o connection.o
[Connect] 2021/06/16 13:42:18.803119457 gcc -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
[Connect] 2021/06/16 13:42:18.803128557 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_doc.cpp -o xml2_doc.o
[Connect] 2021/06/16 13:42:18.803129157 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_init.cpp -o xml2_init.o
[Connect] 2021/06/16 13:42:18.803135158 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_namespace.cpp -o xml2_namespace.o
[Connect] 2021/06/16 13:42:18.803135558 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_node.cpp -o xml2_node.o
[Connect] 2021/06/16 13:42:18.803143458 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_output.cpp -o xml2_output.o
[Connect] 2021/06/16 13:42:18.803144058 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_schema.cpp -o xml2_schema.o
[Connect] 2021/06/16 13:42:18.803149859 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_url.cpp -o xml2_url.o
[Connect] 2021/06/16 13:42:18.803150259 g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t  -I/usr/local/include  -fvisibility=hidden -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c xml2_xpath.cpp -o xml2_xpath.o
[Connect] 2021/06/16 13:42:18.803163760 g++ -std=gnu++11 -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o xml2.so connection.o init.o xml2_doc.o xml2_init.o xml2_namespace.o xml2_node.o xml2_output.o xml2_schema.o xml2_url.o xml2_xpath.o -lxml2 -L/usr/local/lib/R/lib -lR
[Connect] 2021/06/16 13:42:18.803164260 installing to /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4/00LOCK-xml2/00new/xml2/libs
[Connect] 2021/06/16 13:42:18.803170760 ** R
[Connect] 2021/06/16 13:42:18.803171260 ** inst
[Connect] 2021/06/16 13:42:18.803177361 ** tests
[Connect] 2021/06/16 13:42:18.803177861 ** byte-compile and prepare package for lazy loading
[Connect] 2021/06/16 13:42:18.803186161 ** help
[Connect] 2021/06/16 13:42:18.803186861 *** installing help indices
[Connect] 2021/06/16 13:42:18.803192962 ** building package indices
[Connect] 2021/06/16 13:42:18.803193462 ** installing vignettes
[Connect] 2021/06/16 13:42:18.803201462 ** testing if installed package can be loaded from temporary location
[Connect] 2021/06/16 13:42:18.803202262 ** checking absolute paths in shared objects and dynamic libraries
[Connect] 2021/06/16 13:42:18.803208963 mv: cannot move '/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4/00LOCK-xml2/00new/xml2' to '/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.4/xml2': Permission denied
[Connect] 2021/06/16 13:42:18.803212063 ERROR:   moving to final location failed
[Connect] 2021/06/16 13:42:18.803218463 
[Connect] 2021/06/16 13:42:18.803219063 Unable to fully restore the R packages associated with this deployment.
[Connect] 2021/06/16 13:42:18.803225164 Please review the preceding messages to determine which package
[Connect] 2021/06/16 13:42:18.803225964 encountered installation difficulty and the cause of the failure.
[Connect] 2021/06/16 13:42:18.821665166 Warning message:
[Connect] 2021/06/16 13:42:18.821668366 In packrat::restore(overwrite.dirty = TRUE, prompt = FALSE, restart = FALSE) :
[Connect] 2021/06/16 13:42:18.821685867   The most recent snapshot was generated using R version 4.0.2
[Connect] Build error: exit status 1

I've cleared the lock file but I everytime I re-attempt to deploy it happens again. I haven't yet encountered this with any other package and have deployed other apps succesfully.

Any help appreciated on this.

Cheers,

Andy P.