Fix RStudio treating .wdl files as binary via libmagic override (PHP-130724)#332
Merged
Fix RStudio treating .wdl files as binary via libmagic override (PHP-130724)#332
Conversation
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.
yuhuyoyo
approved these changes
Mar 3, 2026
yuhuyoyo
approved these changes
Mar 4, 2026
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.
/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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RStudio displays "File is binary rather than text so cannot be opened by the source editor" when opening
.wdl(Workflow Description Language) files containingimportstatements.Root Cause
libmagic (used by RStudio for file type detection) misidentifies WDL files containing
importstatements asapplication/javascript, because theimport "./path"syntax matches its JavaScript/ES module heuristic. Combined with the unknown.wdlextension, RStudio treats the file as binary.The initially attempted fix of registering
text/x-wdlvia 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/magicrules duringpost-startup.shthat match WDL content patterns and override the MIME type totext/plain. Custom/etc/magicrules 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 headersimport "— WDL import statements without a version header (also matches JS ES modules, but reclassifying astext/plainis harmless since they are still text)Only runs when
rstudio-serveris present, so non-RStudio apps are unaffected. Bothr-analysisandr-analysis-aouapps benefit since they both invokepost-startup.sh.Validation
file --mime-typereturnstext/plain(notapplication/javascript) for.wdlfiles with import statements.wdlfiles withimportstatements open as text in the RStudio editor (no "binary file" error)post-startup.shdoes not create/etc/magicon VS Code or Jupyter apps (thecommand -v rstudio-serverguard skips it)