Skip to content

Fix RStudio treating .wdl files as binary via libmagic override (PHP-130724)#332

Merged
emmarogge merged 7 commits intomasterfrom
emmarogge/PHP-130724
Mar 6, 2026
Merged

Fix RStudio treating .wdl files as binary via libmagic override (PHP-130724)#332
emmarogge merged 7 commits intomasterfrom
emmarogge/PHP-130724

Conversation

@emmarogge
Copy link
Contributor

@emmarogge emmarogge commented Mar 3, 2026

Problem

RStudio displays "File is binary rather than text so cannot be opened by the source editor" when opening .wdl (Workflow Description Language) files containing import statements.

Root Cause

libmagic (used by RStudio for file type detection) misidentifies WDL files containing import statements as application/javascript, because the import "./path" syntax matches its JavaScript/ES module heuristic. Combined with the unknown .wdl extension, RStudio treats the file as binary.

The initially attempted fix of registering text/x-wdl via shared-mime-info (/usr/share/mime/packages/wdl.xml) did not resolve the issue — RStudio relies on libmagic, not the shared MIME database.

Fix

Add custom /etc/magic rules during post-startup.sh that match WDL content patterns and override the MIME type to text/plain. Custom /etc/magic rules take priority over libmagic's built-in database, so the JavaScript detection never fires.

The rules match:

  • version 1.0 / version 1.1 / version draft-2 — standard WDL version headers
  • import " — WDL import statements without a version header (also matches JS ES modules, but reclassifying as text/plain is harmless since they are still text)

Only runs when rstudio-server is present, so non-RStudio apps are unaffected. Both r-analysis and r-analysis-aou apps benefit since they both invoke post-startup.sh.

Validation

  1. CI smoke tests — r-analysis, r-analysis-aou, and non-RStudio app smoke tests pass
  2. libmagic verificationfile --mime-type returns text/plain (not application/javascript) for .wdl files with import statements
  3. RStudio UI test.wdl files with import statements open as text in the RStudio editor (no "binary file" error)
  4. Negative testingpost-startup.sh does not create /etc/magic on VS Code or Jupyter apps (the command -v rstudio-server guard skips it)

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.
@emmarogge emmarogge requested review from kirtanav98 and yuhuyoyo March 3, 2026 18:11
@emmarogge emmarogge marked this pull request as ready for review March 3, 2026 18:39
@emmarogge emmarogge requested review from a team as code owners March 3, 2026 18:39
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
…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.
…-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.
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.
@emmarogge emmarogge changed the title Register .wdl as text MIME type for RStudio (PHP-130724) Fix RStudio treating .wdl files as binary via libmagic override (PHP-130724) Mar 6, 2026
/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.
@emmarogge
Copy link
Contributor Author

I have verified that the fix works -- see Loom screencast. WDL files that start with "version" or "import" statements are able to be opened successfully.

@emmarogge emmarogge merged commit 8e5872e into master Mar 6, 2026
15 checks passed
@emmarogge emmarogge deleted the emmarogge/PHP-130724 branch March 6, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants