INNER CODE UNIT · Python

prune

alper-han/CrossMacro · scripts/ci/flatpak-cache.py:8

def prune(downloads, sources):
    keep = {(source.get('sha512') or source.get('sha256'), source['dest-filename'])
            for source in sources if source.get('type') == 'file'}
    removed = 0
    for directory in downloads.iterdir():
        if directory.is_symlink() or not directory.is_dir():
            continue
        for archive in directory.glob('*.nupkg'):
            if (directory.name, archive.name) not in keep:
                archive.unlink()
                removed += 1
        if not any(directory.iterdir()):
            directory.rmdir()
    return removed


if __name__ == '__main__':
    downloads = Path(os.environ['RUNNER_TEMP']) / 'crossmacro-flatpak-state/downloads'

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…