TIL: fixing folder access from bash

I had a few scary moments the other day – I went to ls ~/Desktop and received a permission denied error!!!!

Ultimately, this wasn’t a “real” problem, just that my terminal program had lost permission to access that directory. But before I figured that out, I went down the rabbit hole of weird Apple file system attributes. (I always forget that the command is xattr and not chattr.)

Things got really confusing when I noticed that the com.apple.macl permission on ~/Desktop had a value of “-1”! And that wasn’t changeable from the terminal! Not even via sudo. Shades of selinux!

Eventually, the rabbit warren led me to a blog post, which quoted a hacker news article about a side effect of pasting a Finder link into a terminal window. Ta da! Copy/paste and the problem was solved. (Of course, I have no idea how the corruption happened, which is a different issue.)

Backing up WSL

I love using WSL – most of my daily work is done there. Almost all the rest done with cloud based tools, so the only thing I need to backup is WSL.

The problem is, my company’s backup software of choice will only handle “real” windows files. It gets quite unhappy if you ask it to backup the WSL virtual drive.

My solution: bup. While not the “latest hotness”, it was trivial to install and run. I ended up writing a wrapper script to add a “--backup” option, and default my destination.

My approach:

  1. Install bup
  2. Designate a Windows directory as a destination. I chose “%HOMEPATH%\bup
  3. Write a wrapper script, to avoid having to remember the bup options and command sequence. The important parts are:
#!/usr/bin/env bash
# wrap bup with my default location
# support my default usage

# use the WSL location of the Windows directory
export BUP_DIR="${BUP_DIR:-/c/Users/hwine/bup}"
real_bup=$(type -ap bup | tail -n +2 | head -1)

if $do_backup; then
    time "${real_bup}" index "${HOME}"
    time "${real_bup}" save -n "${HOME##*/}" "${HOME}"
    "${real_bup}" "$@"

Note that the “bup index” operation is the long pole on any backup. After a typical day’s work, the index takes about 5 minutes, and the actual backup is less than 10 seconds.