# Buggy code
def cmp(rpin, rpout):
    """True if rpin has the same data as rpout

    cmp does not compare file ownership, permissions, or times, or
    examine the contents of a directory.

    """
    check_for_files(rpin, rpout)
    if rpin.isreg():
        if not rpout.isreg():
            return None
        fp1, fp2 = rpin.open("rb"), rpout.open("rb")
        result = cmpfileobj(fp1, fp2)
        if fp1.close() or fp2.close():
            raise RPathException("Error closing file")
        return result
    elif rpin.isdir():
        return rpout.isdir()
    elif rpin.issym():
        return rpout.issym() and (rpin.readlink() == rpout.readlink())
    elif rpin.ischardev():
        return rpout.ischardev() and (rpin.getdevnums() == rpout.getdevnums())
    elif rpin.isblkdev():
        return rpout.isblkdev() and (rpin.getdevnums() == rpout.getdevnums())
    elif rpin.isfifo():
        return rpout.isfifo()
    elif rpin.issock():
        return rpout.issock()
    else:
        raise RPathException("File %s has unknown type" % rpin.get_safepath())


# Traceback (FileNotFoundError)
# rdiff-backup /dev/ /tmp/faketarget/
Exception '[Errno 2] No such file or directory: b'/tmp/faketarget/bus/usb/003/rdiff-backup.tmp.22'' raised of class '<class 'FileNotFoundError'>':
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 390, in error_check_Main
Main(arglist)
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 412, in Main
take_action(rps)
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 348, in take_action
Backup(rps[0], rps[1])
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 437, in Backup
backup.Mirror(rpin, rpout)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 39, in Mirror
DestS.patch(dest_rpath, source_diffiter)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 269, in patch
ITR(diff.index, diff)
File "/usr/lib/python3/dist-packages/rdiff_backup/rorpiter.py", line 313, in __call__
last_branch.fast_process(*args)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 587, in fast_process
if self.patch_to_temp(mirror_rp, diff_rorp, tf):
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 612, in patch_to_temp
result = self.patch_snapshot_to_temp(diff_rorp, new)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 655, in patch_snapshot_to_temp
rpath.copy_attribs(diff_rorp, new)
File "/usr/lib/python3/dist-packages/rdiff_backup/rpath.py", line 240, in copy_attribs
rpout.chown(*rpout.conn.user_group.map_rpath(rpin))
File "/usr/lib/python3/dist-packages/rdiff_backup/rpath.py", line 1192, in chown
self.conn.os.chown(self.path, uid, gid)

Traceback (most recent call last):
File "/usr/bin/rdiff-backup", line 32, in <module>
rdiff_backup.Main.error_check_Main(sys.argv[1:])
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 390, in error_check_Main
Main(arglist)
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 412, in Main
take_action(rps)
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 348, in take_action
Backup(rps[0], rps[1])
File "/usr/lib/python3/dist-packages/rdiff_backup/Main.py", line 437, in Backup
backup.Mirror(rpin, rpout)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 39, in Mirror
DestS.patch(dest_rpath, source_diffiter)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 269, in patch
ITR(diff.index, diff)
File "/usr/lib/python3/dist-packages/rdiff_backup/rorpiter.py", line 313, in __call__
last_branch.fast_process(*args)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 587, in fast_process
if self.patch_to_temp(mirror_rp, diff_rorp, tf):
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 612, in patch_to_temp
result = self.patch_snapshot_to_temp(diff_rorp, new)
File "/usr/lib/python3/dist-packages/rdiff_backup/backup.py", line 655, in patch_snapshot_to_temp
rpath.copy_attribs(diff_rorp, new)
File "/usr/lib/python3/dist-packages/rdiff_backup/rpath.py", line 240, in copy_attribs
rpout.chown(*rpout.conn.user_group.map_rpath(rpin))
File "/usr/lib/python3/dist-packages/rdiff_backup/rpath.py", line 1192, in chown
self.conn.os.chown(self.path, uid, gid)
FileNotFoundError: [Errno 2] No such file or directory: b'/tmp/faketarget/bus/usb/003/rdiff-backup.tmp.22'

# Fixed code
def cmp(rpin, rpout):
    """True if rpin has the same data as rpout

    cmp does not compare file ownership, permissions, or times, or
    examine the contents of a directory.

    """
    check_for_files(rpin, rpout)
    if rpin.isreg():
        if not rpout.isreg():
            return None
        fp1, fp2 = rpin.open("rb"), rpout.open("rb")
        result = cmpfileobj(fp1, fp2)
        if fp1.close() or fp2.close():
            raise RPathException("Error closing file")
        return result
    elif rpin.isdir():
        return rpout.isdir()
    elif rpin.issym():
        return rpout.issym() and (rpin.readlink() == rpout.readlink())
    elif rpin.isdev():
        return rpout.isdev() and (rpin.getdevnums() == rpout.getdevnums())
    elif rpin.isfifo():
        return rpout.isfifo()
    elif rpin.issock():
        return rpout.issock()
    else:
        raise RPathException("File %s has unknown type" % rpin.get_safepath())