The obstinate trash man
This weekend’s pet project was to set up Ubuntu Studio to run on my Macbook Pro.
Ubuntu Studio is a Linux distribution, based on Ubuntu, that comes with lots of audio and video software installed and configured. I have been wanted to play with Ardour, an open source digital audio workstation, and although it will run on a Mac, it runs much better on Linux. So I downloaded and burned a copy of the Ubuntu Studio “Live DVD”. This would allow me to test drive Ubuntu Studio on the Macbook without installing anything on the Macbook’s hard disk. It worked wonderfully, and so I decided to make a bootable “Live USB” stick as well. The Live USB stick acts just like the Live DVD, except it also allows you to save files back to the USB stick (obviously, you can’t save files to a read-only DVD). So I would be able to do my studio work in Linux and save my work when I reboot back into OSX.
I was greeted with a very weird bug in Ubuntu Studio’s desktop system. Whenever I tried to delete a file, I would get the following error:
Unable to find or create trash directory
What a weird error message!
Ubuntu Studio uses the XFCE desktop environment, which follows the Free Desktop’s “Desktop Trash Can Specification“. Yes, there are people who write specifications about how trash cans are supposed to work. There is a utility called “gvfs-trash” that actually handles moving deleted files to the appropriate trash can area. You can run this command from a shell prompt.
$ gvfs-trash somefile
Error trashing file: Unable to find or create trash directory
There’s that same error message.
I ran the same command with “strace” to figure out what it was doing, and I did a little bit of Googling. I found this blog post, which told me most of what I needed.
The gvfs-trash system wanted to find a directory called “.Trash-999” in the top level of the filesystem. It wanted 999 because my user ID number was 999 (run the “id” command to see what your user ID number is). Inside the /.Trash-999 folder, it also wanted two sub-folders named “files” and “info”. All three of these needed to have 700 permissions.
Here’s a one-liner that will do it all:
u=$(id -u) ; g=$(id -g) ; sudo mkdir -m700 /.Trash-$u ; sudo chown $u:$g /.Trash-$u ; mkdir -m700 /.Trash-$u/{files,info}
After that, the desktop system could remove files OK, and the gvfs-trash
command could as well.
That gvfs-trash command might make a good alias!
alias rm='gvfs-trash'
3 comments
Leave a Reply
You must be logged in to post a comment.
Seems like a pretty obvious problem that should have been caught in unit testing or automated QA? Or at worst a beta period? Maybe Ubuntu Studio isn’t quite ready for prime time if this kind of thing is occurring!
The average desktop user isn’t expected to know how to use strace…
I think this only happened because I created a LiveUSB image from the LiveDVD. Remember, the DVD is not writable, and so the root filesystem would not have this trashcan file. I was the one that made it writable when I converted it to a LiveDVD, and that process did not involve creating a trash directory.
I think the gvfs-trash program could fail a little more gracefully, though… like perhaps creating its trashcan directory in /tmp or something.
While looking for something else, I ran across another gvfs- command, “gvfs-open”. This little jewel works just like the Mac OSX “open” command. From a shell prompt, it can open files using whatever is the most appropriate tool for the file. It looks up the file association in the xdg mime-database and runs that program. MP3s open in audacious, M4Vs open in VLC, PDFs open in evince, plain text files open in gedit or gvim.
There is a wrapper program called “xdg-open”, which apparently is the one to use. In a Gnome desktop environment, it calls gvfs-open under the hood.
I have aliased “open” to run “xdg-open”, so I can do Mac-like command-line magic on my Linux boxes.