Example #1
0
def index_file(path):
    for i in os.walk(path):     ##遍历本地目录
        for j in i[2]: 
            try:                ##如果可读,返回当前文件路径+MD5值
                yield os.path.join(i[0],j),check.hashfile(os.path.join(i[0],j))
            except:             ##不可读,返回err信息
                yield os.path.join(i[0],j),"error"
Example #2
0
def index_file(path):
    result={}
    for i in os.walk(path):
        for j in i[2]:
            try: 
                yield os.path.join(i[0],j),check.hashfile(os.path.join(i[0],j))
            except:
                yield os.path.join(i[0],j),"error"
Example #3
0
def FileOK():
    file,hash=eval(request.body.read())
#    print(result)
    if check.hashfile(base+file)==hash:
        db.set(file,hash)
        return("File Hash Checked OK")
        pass
    else:
        os.remove(base+file)
        return "Hash Checked Not OK,The file deleted"
    pass
Example #4
0
def FileSync(path): 
    for i,j in index_file(path):    ##获取一个文件信息
        if j=='error':              ##错误就忽略
            continue
        req=urllib.request.urlopen(host+'checkdate',i.encode()).read() ##从服务器获取本文件的日期
        print(req,j)
        if req.decode()==str(j):         ##如果md5与本地的相同,忽略,否则上传
            print('File "{}" already in server passed'.format(i))
        else:
            print(Upload(i))
            k=check.hashfile(i)
            print(CheckFile(i,k,j))
Example #5
0
def FileOK():
    file,hash,date=eval(request.body.read())
    print('debug:'+file+hash+str(date))
    if check.hashfile(base+file)==hash:     ##如果发来的文件md5==本地算出的MD5
        if db.llen(file)>0:
            print('db.llen'+str(db.llen(file))+file)
            db.ltrim(file,0,0)
        db.lpush(file,date,hash)                   ##就存储到数据库
        return("File Hash Checked OK")
        pass
    else:
        os.remove(base+file)                ##如果不一致就删掉文件
        return "Hash Checked Not OK,The file deleted"
    pass