Dev Notes

Various Cheat Sheets and Resources by David Egan/Carawebs.

Delete files in Atom under Ubuntu 16.04


Atom, Sysadmin, Ubuntu
David Egan

Atom is my editor of choice - I really enjoy working in it, to the point where I even write content and prepare client reports from within Atom (I can build in git logs, write in Markdown, and convert to PDF for the client). Going back to Tiny MCE in WordPress feels horrible! Atom is free, open source and very hackable - but I recently had a problem with file deletion.

Trashing Files

When trying to delete files in Atom 1.8.0 running on Ubuntu Xenial, you may experience a problem whereby file deletion is not possible. The error message returned by Atom suggests that gvfs-trash is not installed:

The following file couldn’t be moved to trash (is gvfs-trash installed?)

Debugging Steps

Check that gvfs-trash is working by opening a terminal & moving to a development directory - in this case, var/www/html/devsite - and attempting to delete a file:

gvfs-trash filename

# this returns:
Error trashing file: Unable to find or create trash directory

This gives a clue - it looks like:

  1. Atom uses gvfs-trash to send files to Trash on delete
  2. When the file to be deleted is located outside the home directory, there is a problem - the gvfs-trash process fails

It would be good if Atom could return the gvfs-trash error message, as this gives just enough information to hint towards a solution.

Solution

Create a new Trash directory that can be accessed from outside the user’s home directory:

# Create a Trash directory (with some subdirectories) in root
sudo mkdir -p /.Trash-1000/{expunged,files,info}

# Give ownership of this to your user:
sudo chown -R $USER /.Trash-1000

That’s it - problem solved!

The answer had been staring me in the face for weeks - some of my repos are in my home directory (mainly BASH scripts and system utilities) and files in these directories were deleting without issue. It didn’t dawn on me that the issue only cropped up in my Apache doc root (/var/www/html/*). Facepalm.

Posting this here to prevent repeating myself the next time I set up a development environment.

Resources

Useful gvfs-trash Commands

# Move oldfile to trash
gvfs-trash oldfile

# See contents of trash:
gvfs-ls trash://

# Take out the trash:
gvfs-trash --empty

comments powered by Disqus