SUSYUSTC / MathTranslate

translate scientific papers in latex, especially arxiv papers
https://github.com/SUSYUSTC/MathTranslate
Apache License 2.0
1.04k stars 69 forks source link

## bugfix: ValueError: ZIP does not support timestamps before 1980 #82

Closed rotcx closed 8 months ago

rotcx commented 8 months ago

case: 2107.00630v6

fix: image

## bugfix: ValueError: ZIP does not support timestamps before 1980
import time
def zipdir(dir, output_path):
    # ziph is zipfile handle
    zipf = zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED)
    for file in loop_files(dir):
        rel_path = os.path.relpath(file, dir)

        # 检查并修复文件时间戳
        timestamp = os.path.getmtime(file)
        if timestamp < time.mktime((1980, 1, 1, 0, 0, 0, 0, 0, 0)):
            os.utime(file, (time.mktime((1980, 1, 1, 0, 0, 0, 0, 0, 0)), time.mktime((1980, 1, 1, 0, 0, 0, 0, 0, 0))))

        zipf.write(file, arcname=rel_path)
    zipf.close()

def zipdir0(dir, output_path):
    # ziph is zipfile handle
    zipf = zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED)
    for file in loop_files(dir):
        rel_path = os.path.relpath(file, dir)
        zipf.write(file, arcname=rel_path)

image