def rename(self, old_path, new_path): # {{{3
    try:
      self.__log_call('rename', 'rename(%r -> %r)', old_path, new_path)
      if self.read_only: return -errno.EROFS
      # Try to remove the existing target path (if if exists).
      # NB: This also makes sure target directories are empty.
      try:
        self.__remove(new_path, check_empty=True)
      except __HOLE__, e:
        # Ignore errno.ENOENT, re raise other exceptions.
        if e.errno != errno.ENOENT: raise
      # Link the new path to the same inode as the old path.
      self.link(old_path, new_path, nested=True)
      # Finally unlink the old path.
      self.unlink(old_path, nested=True)
      self.__commit_changes()
      self.__gc_hook()
      return 0
    except Exception, e:
      self.__rollback_changes()
      return self.__except_to_status('rename', e, errno.ENOENT)
dataset/ETHPy150Open xolox/dedupfs/dedupfs.py/DedupFS.rename