Skip to content

Commit

Permalink
Handle empty rstudio-prefs.json
Browse files Browse the repository at this point in the history
Based on [feedback](https://bennettoxford.slack.com/archives/C069SADHP1Q/p1716892511090679) from @alschaffer there appear to be occasions when `rstudio-prefs.json` is empty at the time this script runs. 

In those instances the previous call to `jq` would return a null output and so the working directory preference would not be set.

We don't yet know what these circumstances are.

This PR proposes a way to handle the empty file, we need to carefully test to ensure this setting persists beyond whatever process adds to this file in the circumstances described above.
  • Loading branch information
Jongmassey authored May 28, 2024
1 parent bc24007 commit f42295a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ set -euo pipefail
#set R working directory
! grep -q "$1" $R_HOME/etc/Rprofile.site && sudo tee -a $R_HOME/etc/Rprofile.site <<< "setwd(\"$1\")"
#set RStudio working directory
! grep -q "$1" ~/.config/rstudio/rstudio-prefs.json && cat ~/.config/rstudio/rstudio-prefs.json | jq ". + {\"initial_working_directory\":\"$1\"}" > ~/.config/rstudio/rstudio-prefs.json
if [ ! -s ~/.config/rstudio/rstudio-prefs.json ]; then nullinput="-n"; fi;
! grep -q "$1" ~/.config/rstudio/rstudio-prefs.json && cat ~/.config/rstudio/rstudio-prefs.json | jq "$nullinput" ". + {\"initial_working_directory\":\"$1\"}" > ~/.config/rstudio/rstudio-prefs.json
#download and extract latest ehrql source
wget https://github.com/opensafely-core/ehrql/archive/main.zip -P .devcontainer
Expand Down

0 comments on commit f42295a

Please sign in to comment.