24

Usually I'm avoiding snap-based applications, but sometime I need them.

For example - Markdown Lint Tool is shipped only as Snap named mdl.

It works great when files are in home folder -

$ echo "# header" > ~/test.md
$ /snap/bin/mdl ~/test.md ; echo $?
0

but it fails when file is located in /tmp directory:

$ echo "# header" > /tmp/test.md
$ cat /tmp/test.md
# header
$ /snap/bin/mdl /tmp/test.md
/snap/mdl/140/lib/ruby/gems/2.4.0/gems/mdl-0.9.0/lib/mdl/doc.rb:57:in `read': No such file or directory @ rb_sysopen - /tmp/test.md (Errno::ENOENT)
    from /snap/mdl/140/lib/ruby/gems/2.4.0/gems/mdl-0.9.0/lib/mdl/doc.rb:57:in `new_from_file'
    from /snap/mdl/140/lib/ruby/gems/2.4.0/gems/mdl-0.9.0/lib/mdl.rb:75:in `block in run'
    from /snap/mdl/140/lib/ruby/gems/2.4.0/gems/mdl-0.9.0/lib/mdl.rb:73:in `each'
    from /snap/mdl/140/lib/ruby/gems/2.4.0/gems/mdl-0.9.0/lib/mdl.rb:73:in `run'
    from /snap/mdl/140/lib/ruby/gems/2.4.0/gems/mdl-0.9.0/bin/mdl:10:in `<top (required)>'
    from /snap/mdl/140/bin/mdl:23:in `load'
    from /snap/mdl/140/bin/mdl:23:in `<main>'

For this particular application there are no options for snap connect:

$ snap connections | grep mdl
home                      mdl:home                             :home                                 -

Also I can't install it as classic:

$ snap install mdl --classic 
Warning: flag --classic ignored for strictly confined snap mdl

mdl 0.9.0 from Snapcrafters installed

What should I do to give Snap application full access to the /tmp folder?
Does it happen by Snap design or not?

N0rbert
  • 103,523
  • 1
    There was a long discussion about this awhile ago: https://askubuntu.com/questions/1033344/how-to-give-snaps-access-to-somedir. It doesn't sound promising. – ajgringo619 Aug 01 '20 at 19:35
  • I checked snap by using terminal and "snap find mdl" did not return a classic version as being offered. That is one thing. Another, (this copied and pasted from GitHub)Markdownlint is written in ruby and is distributed as a rubygem. As long as you have a relatively up to date ruby on your system, markdownlint will be simple to install and use. You have 2 options to install it:

    To install from rubygems, run:

    gem install mdl

    – Thomas Byers Aug 03 '20 at 18:27
  • Thanks @ThomasByers , but let's get snap problem solved. I know about Ruby and Gem. IMHO the problem has wider audience in terms of affected applications. – N0rbert Aug 03 '20 at 19:11

2 Answers2

17

It seems you may be looking for the "proper" way to solve the issue caused with snaps...

but if you were looking for a workaround so you can use your tmp directory, you could:

mkdir /home/you/tmp
sudo mount --bind /tmp /home/you/tmp/

mdl will have full access to the /tmp directory via the /home/you/tmp mountpoint:

echo "# header" > /home/you/tmp/test.md
mdl /home/you/tmp/test.md

To make it permanent you can add this line to the /etc/fstab:

 # <file system> <mount point>   <type>  <options>       <dump>  <pass>
/tmp        /home/you/tmp   auto    bind    0   3

and rebuild the initrd with sudo update-initramfs -u -k all .

N0rbert
  • 103,523
WU-TANG
  • 3,326
  • It really works, a bit hacky. – N0rbert Aug 03 '20 at 20:46
  • @N0rbert yeah I was thinking you may feel that way... I haven't been able to come up with anything else with the cross partition deal and snaps... Like you, I just try to avoid them. – WU-TANG Aug 03 '20 at 20:49
  • I have added the suggested line to fstab, so for now it is permanent. Thank you. Bounty will follow :) – N0rbert Aug 03 '20 at 21:00
  • 3
    Holy shit, Ubuntu broke /tmp and nobody seems to care? The fix involves fstab? This is outrageous?! – mlissner Jan 07 '22 at 19:01
  • 2
    @mlissner... this isn't about /tmp... it's about any directory other than /home/username and snaps... It's also not a fix, it is a workaround to work with snaps in the method that the OP desired... you're not reading the question – WU-TANG Jan 08 '22 at 00:23
  • 3
    I understand the question. The person wants to use /tmp in a perfectly normal way. I'm trying to use /tmp from Firefox and I can't. Phrase it however you want, but in my book if I can't use /tmp from an application, something is very broken and I'm shocked Ubuntu thinks this is fine. – mlissner Jan 08 '22 at 00:48
  • 3
    you clearly are not reading the question. you aren't even reading the answer. hell, you didn't even read my comment. Someone else can spend their time reiterating, after this... it has NOTHING to do with /tmp... it is SNAPS + ANY OTHER DIRECTORY outside of the user's home directory... So no, /tmp is not "broken", that is a ridiculous thing to say. If that was the case, then every other (non-home) directory in which the user has r/w privileges, is also broken... I think most people understand that /tmp is not the problem, perhaps that's why "nobody seems to care" – WU-TANG Jan 08 '22 at 01:37
  • 1
    Hi @WU-TANG thanks for the trick! Q: Could you clarify why "rebuild the initrd with sudo update-initramfs -u -k all" is necessary? Isn't adding the mount to fstab enough? Thanks! ^_^ – Gerard Bosch Nov 14 '22 at 09:56
  • @GerardBosch hello.... I'm not sure... If you view the edits, the portion "to make it permanent...." was edited in by the OP "N0rbert". I'd be interested in the logic there, I just never got around to asking him... and then 2 years went by – WU-TANG Nov 19 '22 at 04:24
  • I mounted the /tmp as suggested. I am tying to open a .pdf attachment from thunderbird with okular (snap). When double-clicking on the attachment a file is created in /tmp/pid-xxx/attachment.pdf, but I get an error message from okular. I can open the created file double clicking on it though. Is it a connections problem? – giammi56 Nov 30 '22 at 17:29
  • @giammi56 I am not sure, but it doesnt sound like it.. If you can create the file in /tmp with the snap software, then the problem the OP was having is seemingly solved. Especially if that part wasnt working for you before. You are probably going to have to look into what the message is saying. – WU-TANG Dec 02 '22 at 09:23
  • @WU-TANG I am able to save a .pdf from Okular snap in /tmp and read if double-clicking on it from Nautilus. The connection is broken when prompting the reading from thunderbird. – giammi56 Dec 02 '22 at 09:36
  • use mkdir /home/$USER/tmp and sudo mount --bind /tmp /home/$USER/tmp/ (this way your username is automatically inserted) – Stefan Krüger s-light Sep 17 '24 at 10:56
  • have a look at the answer: https://askubuntu.com/a/1460989/207905 this worked for me :-) – Stefan Krüger s-light Sep 18 '24 at 06:21
  • @StefanKrügers-light... The solution you are referencing doesn't answer the question. The question is: how can I get snap to access /tmp? Snap can naturally access your home directory, we already know that. So simply making a directory in your home directory called tmp doesn't really solve the specific issue. The link you provided (and even the other answer on this very post) is merely doing just that... it's a bit of a placebo. I'm sure after some time, those satisfied utilizing it, will realize that it wasn't doing what they thought... or they really didn't want to access /tmp. – WU-TANG Sep 19 '24 at 21:11
  • @WU-TANG yeah i know - it is a work around.. that has its own draw-backs. and we already now that it is NOT POSSIBLE to access /tmp from snap. That is true for your answer too! maybe a combination of the linked answer and this answer here could work.. (as fare as i understand this here creates a link between the real /tmp and the ~/tmp folder. but misses to set the tmp env setting so the apps know where to write the tmp files - the linked answer at least for me worked for my VSCode and Firefox combination.. (that was where i encountered the problem.) – Stefan Krüger s-light Sep 24 '24 at 09:28
7

I'm usually very supportive of change and of Ubuntu, but if, like me, you find this really annoying, the fix I came up with is to add a directory to my home:

mkdir /home/mlissner/tmp

And to add a crontab to nuke it on reboot:

sudo crontab -e

Then add:

@reboot rm -rf /home/mlissner/tmp/*

Having to do this is really dumb.

I'm all for sandboxing and security. I'm all for change, but this removes an important use case of "Save this file here, and then delete it later without me thinking about it."

It's also really buggy from a user perspective. You can save something from Firefox into /tmp, no errors. But then when you try to find that thing in the file browser, it doesn't exist. WTF.

Count me very annoyed.

mlissner
  • 2,323