Staging
v0.5.1
swh:1:snp:635f4099902912592851108bcac178ff574f7c5f
Raw File
Tip revision: 47f075d96b9c205c6731f8599206172c3e209242 authored by Benjamin Peterson on 01 December 2020, 15:05:57 UTC
[3.7] Bumps [actions/cache](https://github.com/actions/cache) from v1 to v2.1.3. (GH-23596)
Tip revision: 47f075d
bkfile.py
from builtins import open as _orig_open

def open(file, mode='r', bufsize=-1):
    if 'w' not in mode:
        return _orig_open(file, mode, bufsize)
    import os
    backup = file + '~'
    try:
        os.unlink(backup)
    except OSError:
        pass
    try:
        os.rename(file, backup)
    except OSError:
        return _orig_open(file, mode, bufsize)
    f = _orig_open(file, mode, bufsize)
    _orig_close = f.close
    def close():
        _orig_close()
        import filecmp
        if filecmp.cmp(backup, file, shallow=False):
            import os
            os.unlink(file)
            os.rename(backup, file)
    f.close = close
    return f
back to top