OSError with duply on OS X

Once in a while when running a duplicity backup via the duply profile manager, I would get an error like this:

--- Start running command BKP at 12:40:44.000 ---
Reading globbing filelist /Users/andrew/.duply/marvin-cloudfiles/exclude  
Synchronizing remote metadata to local cache...  
Copying duplicity-full-signatures.20140217T200006Z.sigtar.gpg to local cache.  
Traceback (most recent call last):  
  File "/usr/local/Cellar/duplicity/0.6.23/libexec/bin/duplicity", line 1489, in <module>
  File "/usr/local/Cellar/duplicity/0.6.23/libexec/bin/duplicity", line 1483, in with_tempdir
  File "/usr/local/Cellar/duplicity/0.6.23/libexec/bin/duplicity", line 1332, in main
  File "/usr/local/Cellar/duplicity/0.6.23/libexec/bin/duplicity", line 1361, in do_backup
  File "/usr/local/Cellar/duplicity/0.6.23/libexec/bin/duplicity", line 1142, in sync_archive
  File "/usr/local/Cellar/duplicity/0.6.23/libexec/bin/duplicity", line 1091, in copy_to_local
  File "/usr/local/lib/python2.7/site-packages/duplicity/path.py", line 618, in move
  File "/usr/local/lib/python2.7/site-packages/duplicity/path.py", line 444, in copy
  File "/usr/local/lib/python2.7/site-packages/duplicity/path.py", line 449, in copy_attribs
    util.maybe_ignore_errors(lambda: os.chown(other.name, self.stat.st_uid, self.stat.st_gid))
  File "/usr/local/lib/python2.7/site-packages/duplicity/util.py", line 82, in maybe_ignore_errors
    return fn()
  File "/usr/local/lib/python2.7/site-packages/duplicity/path.py", line 449, in <lambda>
    util.maybe_ignore_errors(lambda: os.chown(other.name, self.stat.st_uid, self.stat.st_gid))
OSError: [Errno 1] Operation not permitted: '/Users/andrew/.cache/duplicity/duply_marvin-cloudfiles/duplicity-full-signatures.20140217T200006Z.sigtar.gz'

12:41:31.000 Task 'BKP' failed with exit code '30'.  
--- Finished state FAILED 'code 30' at 12:41:31.000 - Runtime 00:00:47.000 ---

Clearly it iss an issue with duplicity failing to perform a chown, and thus bailing out. Fortunately, Lee Verberne's post enlightened me to what was happening: duplicity was copying from the temp directory (owned by root) to a user cache directory, and of course, as a user program, failed to chown from root to user.

Lee's fix (export TMPDIR="$HOME.cache/tmp") works great if you're calling duplicity directly, as it inherits the environment. However, duply won't forward the variable onto duplicity, but there is fortunately a --tempdir parameter for duplicity. To get duply to set this, add the following line to your duply profile's conf file:

DUPL_PARAMS="$DUPL_PARAMS --tempdir=$HOME/.cache/tmp"  

Just like that, no more OSError, err, errors.