__init__.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:finja 作者: adfinis-sygroup 项目源码 文件源码
def index_file(db, file_path, update = False):
    global _index_count
    if six.PY2:
        if not isinstance(file_path, unicode):  # noqa
            file_path = unicode(file_path, encoding="UTF-8")  # noqa
    con        = db[0]
    # Bad symlinks etc.
    try:
        stat_res = os.stat(file_path)
    except OSError:
        if not update:
            print("%s: not found, skipping" % (file_path,))
        return
    if not stat.S_ISREG(stat_res[stat.ST_MODE]):
        if not update:
            print("%s: not a plain file, skipping" % (file_path,))
        return
    inode_mod     = (stat_res[stat.ST_INO] * stat_res[stat.ST_MTIME]) % 2 ** 62
    old_inode_mod = None
    old_md5       = None
    file_         = None
    with con:
        res = con.execute(_find_file, (file_path,)).fetchall()
        if res:
            file_         = res[0][0]
            old_inode_mod = res[0][1]
            old_md5       = res[0][2]
    if old_inode_mod != inode_mod:
        do_index, file_ = check_file(
            con, file_, file_path, inode_mod, old_md5, update
        )
        if not do_index:
            return
        encoding = read_index(db, file_, file_path, update)
        con.execute(_update_file_info, (encoding, file_path))
    else:
        if not update:
            print("%s: uptodate" % (file_path,))
        with con:
            con.execute(_mark_found, (file_path,))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号