def _insert_into_database(self, root, f, mode, prefix=None, unsplitable_name=None):
        """
        Does the actual insertion into the database.
        """
        path = os.path.abspath(os.path.join(root, f))
        if not os.access(path, os.R_OK):
            logger.warning('Path %r is not accessible, skipping' % path)
            return
        
        if mode == 'exact':
            key = self.keyify(prefix, f)
            if key in self.db:
                self.db[key] = self.db[key] + [path]
            else:
                self.db[key] = [path]
        else:
            normalized_filename = self.normalize_filename(f)
            size = os.path.getsize(path)
            
            if mode.startswith('hash_'):
                if mode == 'hash_store_name': # the size can vary, name is exact. I.e. filename to path mapping
                    key = self.keyify(normalized_filename)
                elif mode == 'hash_store_size': # the name can vary, size is exact (same db can be used for slow-mo). I.e. size to path mapping
                    key = str('s:%i' % size)
                self.db[key] = self.db.get(key, []) + [path]
            else:
                if mode == 'unsplitable':
                    split_root = root.split(os.sep)
                    p_index = len(split_root) - split_root[::-1].index(unsplitable_name) - 1
                    p = [self.normalize_filename(x) for x in split_root[p_index:]] + [normalized_filename]
                    
                    key = self.keyify(size, *p)
                elif mode == 'normal':
                    key = self.keyify(size, normalized_filename)
                
                if key in self.db: # check if same file
                    old_inode = os.stat(self.db[key]).st_ino
                    new_inode = os.stat(path).st_ino
                    if old_inode != new_inode:
                        logger.warning('Duplicate key %s and %s' % (path, self.db[key]))
    
                self.db[key] = path
dataset/ETHPy150Open JohnDoee/autotorrent/autotorrent/db.py/Database._insert_into_database/original