Skip to content

Commit 9252e29

Browse files
authored
Fix RStudio treating .wdl files as binary via libmagic override (PHP-130724) (#332)
* Register .wdl as text MIME type for RStudio (PHP-130724) RStudio misidentifies .wdl files containing 'import' statements as binary/JavaScript, preventing users from opening them. Fix by registering .wdl as text/x-wdl via the freedesktop shared-mime-info system during post-startup, so extension-based MIME resolution takes priority over content-based detection. Only runs when rstudio-server is present, so non-RStudio apps are unaffected. * Move .wdl MIME fix to Dockerfiles for reliability (PHP-130724) The startup script approach was unreliable because post-startup.sh could fail before reaching the MIME registration block. Move the fix to Dockerfiles so it's baked into the container image at build time, guaranteeing the MIME type is registered before RStudio Server starts. Changes: - Create Dockerfile for r-analysis with .wdl MIME type registration - Update docker-compose.yaml to use build context - Add MIME fix to r-analysis-aou Dockerfile - Remove runtime MIME registration from post-startup.sh * Revert Dockerfile approach; place MIME fix early in post-startup.sh (PHP-130724) The Dockerfile approach caused build failures because adding build: to docker-compose.yaml changes how devcontainer CLI applies features (injecting them as Dockerfile build steps), which conflicts with /opt/conda already existing in the tidyverse base image. Instead, register the .wdl MIME type in post-startup.sh at the very beginning — right after logging setup but before apt-get update and other network-dependent steps that may fail. This ensures the MIME type is registered even if later startup steps encounter errors. * Remove unintended files from commit * Use libmagic override instead of MIME database for WDL detection (PHP-130724) Replace shared-mime-info XML registration with a custom /etc/magic rule. The root cause is that libmagic misidentifies WDL files containing 'import' statements as application/javascript, causing RStudio to treat them as binary. The magic rule matches WDL version headers (1.0, 1.1, draft-2) and overrides the MIME type to text/plain. * Also override libmagic for WDL files starting with import (PHP-130724) WDL files without a version header that start with an import statement are also misidentified as application/javascript by libmagic. Add a catch-all rule for files starting with 'import "'. Reclassifying JavaScript ES modules as text/plain is harmless. * Remove mkdir for /etc/magic — it already exists as a file (PHP-130724) /etc/magic is a regular file used by libmagic for custom rules, not a directory. The mkdir -p call fails when the file already exists, causing the post-startup script to exit with an error.
1 parent c0c151c commit 9252e29

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

startupscript/post-startup.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,35 @@ ${RUN_AS_LOGIN_USER} "ln -sf '${USER_WORKBENCH_CONFIG_DIR}' '${USER_WORKBENCH_LE
7979
exec > >(tee -a "${POST_STARTUP_OUTPUT_FILE}") # Append output to the file and print to terminal
8080
exec 2> >(tee -a "${POST_STARTUP_OUTPUT_FILE}" >&2) # Append errors to the file and print to terminal
8181

82+
###############################
83+
# RStudio file type configuration
84+
###############################
85+
# Override libmagic detection for file types that are misidentified as binary
86+
# (PHP-130724). WDL files containing "import" statements are detected as
87+
# "application/javascript" by libmagic, causing RStudio to refuse to open them.
88+
# Adding a custom magic rule ensures they are detected as text/plain instead.
89+
# This must run before apt-get and other network-dependent steps that may fail.
90+
if command -v rstudio-server &> /dev/null; then
91+
emit "Configuring file type detection for RStudio..."
92+
cat > /etc/magic << 'MAGIC_EOF'
93+
# WDL (Workflow Description Language) files - override JavaScript detection.
94+
# libmagic misidentifies WDL import statements as JavaScript/ES modules,
95+
# which causes RStudio to treat .wdl files as binary.
96+
# Rules for files starting with a version declaration:
97+
0 string version\ 1.0 Workflow Description Language source
98+
!:mime text/plain
99+
0 string version\ 1.1 Workflow Description Language source
100+
!:mime text/plain
101+
0 string version\ draft-2 Workflow Description Language source
102+
!:mime text/plain
103+
# Rule for files starting with an import (no version header).
104+
# This also matches JavaScript ES module files, but reclassifying them
105+
# as text/plain is harmless — they are still text.
106+
0 string import\ " Text source with imports
107+
!:mime text/plain
108+
MAGIC_EOF
109+
fi
110+
82111
# The apt package index may not be clean when we run; resynchronize
83112
if type apk > /dev/null 2>&1; then
84113
apk update

0 commit comments

Comments
 (0)