How to adjust files and folders inside the Snap file system

Tonight I stumbled into the fact that Atlassian Crowd 4 authentication did not work well with Rocketchat.

On Github.com I found a patch from a fellow contributor (thanks Codemighty!). Unfortunately I could not directly apply this patch, because we host RocketChat inside a Snap for automated updates. This Snap filesystem mounts in read-only. So I was stuck and had no idea how to mount the Snap file system in write mode. Luckily I discovered a workaround for this problem.

How to adjust files in Snap filesystem

In below steps I will guide you how you can extract the contents of the Snap filesystem to a folder. In this folder you can apply your patches and after that you can run the Snap from that folder.

First you need to know which Snap you need to work on. For this type:

snap list

Example output:

NameVersionRevTrackingPublisherNotes
core16-2.46.19993latest/stablecanonical✓core
core18202007241885latest/stablecanonical✓base
rocketchat-server3.6.214423.x/stablerocketchat✓-
snapcraft4.35472latest/stablecanonical✓classic

Now I know that I need to patch the 1442 revision of the rocketchat-server, great. Let the fun begin!

Extract the Snap file system to a working folder

sudo unsquashfs -d /home/basvanbeek/snap-tests/rocketchat-server /var/lib/snapd/snaps/rocketchat-server_1442.snap

Jump into the working folder

cd /home/basvanbeek/snap-tests/rocketchat-server

Patch RocketChat to work with Atlassian Crowd 4

vi programs/server/npm/node_modules/atlassian-crowd/lib/index.js

Rename line 130:

if (response.headers['content-type'] !== "application/json") {

To:

if ( !(/application\/json/.test(response.headers['content-type'])) ) {

Save and quit by typing: :wq

Start Snap again, but this time from the working folder

sudo snap try /home/basvanbeek/snap-tests/rocketchat-server