Closed ArnaudBru closed 10 months ago
I am open to suggestions. If you know of a workable solution, a PR would be appreciated.
This is what we currently do. Linux seems to love to make this increasingly more difficult to abstract: https://github.com/facelessuser/MarkdownPreview/blob/master/browser.py#L60.
I guess this isn't a "browser opening" issue as much as it is a tmp file creation issue. As I have no way of knowing what specific tmp a browser can see or does not see, we'd have to make some tmp file relocation feature where the user can specify where they want their tmp to be so their browser can see it. I'm not sure I'm interested in jumping through hoops to try and automatically figure out what specific tmp we should use, so having the user specify it is probably going to be the compromise.
If anyone wants to tackle this, I'm happy to take a PR, otherwise, I'll put it on my list and see when I have time to update this.
@ArnaudBru I forgot we already abstracted temp files, try out this setting: https://github.com/facelessuser/MarkdownPreview/blob/master/MarkdownPreview.sublime-settings#L317
As it appears the temp folder can already be controlled, closing this as no change. If this is not sufficient feel free to reopen, but please provide details as to why it is not sufficient.
For Ubuntu 22.04
, where firefox is provided by snap
, I added an entry in /etc/fstab
for a bind
mount of the /run/user/1000/home.tmp
directory at ~/tmp
. The mount is done with a systemd
user unit. The /run/user/1000
directory is basically a tmpfs
mount for the user 1000
that is automatically done by pam_systemd
when user logs in (mount | grep tmpfs
) and will be cleared automatically on reboot, so better to use it than using a real directory which will have to be cleared manually or some other way.
Run sudo nano /etc/fstab
add /run/user/1000/home.tmp /home/<user>/tmp none bind,noauto,user,exec,x-gvfs-hide 0 0
and save and exit (goodluck!). The <user>
needs to be replaced by your username and replace 1000
if your uid is different (id -u
). Check mount
options info in its man page. The bind
options is so that a bind
mount is created. The noauto
option so that mount is not automatically done on boot, check notes below. The user
option so that root is not required to mount and it can be done by the user level systemd
service. The exec
option so that binaries can be executed, it needs to be explicitly specified as user
option implies noexec
by default. The x-gvfs-hide
option so that mount is not listed in the file manager sidebar, check gvfs
docs.
Run mkdir -p ~/.config/systemd/user && nano ~/.config/systemd/user/tmp-mount.service
and paste following and save and exit. The %U
expands to user id and %h
expands to home directory, check systemd
specifiers.
[Unit]
Description=Mount ~/tmp directory
[Service]
ExecStart=/bin/bash -c 'mkdir -p /run/user/%U/home.tmp && /bin/mount %h/tmp'
ExecStop=/bin/umount %h/tmp
RemainAfterExit=yes
[Install]
WantedBy=default.target
Enable the service with systemctl --user enable tmp-mount.service
so that mount is automatically done on reboots.
Start the service with systemctl --user start tmp-mount.service
so that mount is done now without requiring a reboot. You can check service status with systemctl --user status tmp-mount.service
and can unmount with systemctl --user stop tmp-mount.service
if needed.
Check mount with mount | grep /home
and it should show something like following.
tmpfs on /home/<user>/tmp type tmpfs (rw,nosuid,nodev,relatime,size=3265312k,nr_inodes=816328,mode=700,uid=1000,gid=1000,inode64,user=<user>,x-gvfs-hide)
"path_tempfile": "/home/<user>/tmp/MarkdownPreview"
to MarkdownPreview
settings. It doesn't expand environmental variables like $HOME
, so will require hard coding the path.snaps
by default, only directories under the home ($HOME
) directory are readable if they do not start with a dot .
(non-hidden), so ~/.tmp
or directly using /run/user/1000
will not work. A bind
mount to /run/user/1000/*
must be created, as a symlink will not work either as realpath
will be checked.bind
mount /run/user/1000/home.tmp
instead of /run/user/1000
, since otherwise /home/<user>/tmp/gvfs
and /home/<user>/tmp/doc
mounts will be translated from /run/user/1000/gvfs
and /run/user/1000/doc
and since their mounts do not have the x-gvfs-hide
mount option, they would get listed in the file manager sidebar.noauto
mount option must be used so that /run/user/1000/home.tmp
directory is not mounted at boot since it normally wouldn't exist and if mounted at boot with root, /run/user/1000
will automatically be created with root
as the owner and the systemd --user
instance run by pam_systemd
will fail during login Runtime directory '/run/user/1000' is not owned by UID 1000, as it should. Trying to run as user instance, but $XDG_RUNTIME_DIR is not set
error. You can check failures with systemctl status user@1000
if it's happening. If this happens, firefox if installed with snap
will also fail to launch with errors like /user.slice/user-1000.slice/session-1.scope is not a snap cgroup
.Hopefully, this helps others.
Edit: Finally had to reboot my laptop and mounting with /etc/fstab
automatically will not work and systemd
user unit should be used instead.
When I run the preview in browser command from SublimeText, I get a file not found error.
The file is created in
/tmp
but I cannot open it in my browser from there, this is likely due to the fact that Linux supports "mount namespaces" which allow different processes to have different views of what's mounted where (e.g. this is how containers such as Docker or LXC are implemented).Firefox was installed through the snap system, which isolates each app in its own container with limited access to the real system – what Firefox sees as /tmp inside the container corresponds to /tmp/snap.firefox/tmp (or /tmp/snap-private-tmp/snap.firefox/tmp) outside the container.
This issue happens with Ubuntu 22.04 Firefox 116.0.3 (64-bit) Sublime Text Build 4152 MarkdownPreview v2.4.3