Applies remote delta to local file.

def patch(self, delta):
        "Applies remote delta to local file."
        # Create a temp file in which to store our synced copy. We will handle
        # deleting it manually, since we may move it instead.
        with (tempfile.NamedTemporaryFile(prefix='.sync',
              suffix=os.path.basename(self.path),
              dir=os.path.dirname(self.path), delete=False)) as output:
            try:
                # Open the local file, data may be read from it.
                with open(self.path, 'rb') as reference:
                    # Patch the local file into our temporary file.
                    r = librsync.patch(reference, delta, output)
                    os.rename(output.name, self.path)
                    return r
            finally:
                try:
                    os.remove(output.name)
                except OSError as e:
                    if e.errno != errno.ENOENT:
                        raise