def test_get_files_to_remove_add_files_with_different_sha():
    dci_files_list = {
        "directories": [],
        "files": [
            {
                "name": "a",
                "path": "",
                "sha256":
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                "size": 0,
            },
            {
                "name": "b",
                "path": "",
                "sha256":
                "7848a92f625831b29caa0c74770603b78f8f6877541f803c33aa3741f946712d",
                "size": 7123,
            },
            {
                "name": "c",
                "path": "subfolder",
                "sha256":
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                "size": 0,
            },
        ],
        "symlinks": [],
    }
    test_dir = os.path.dirname(os.path.abspath(__file__))
    path = os.path.join(test_dir, "data", "repo")
    files_to_remove = [os.path.join(path, "b")]
    assert get_files_to_remove(dci_files_list, path) == files_to_remove
def test_get_files_to_remove():
    dci_files_list = {
        "directories": [],
        "files": [
            {
                "name": "b",
                "path": "",
                "sha256":
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                "size": 0,
            },
            {
                "name": "c",
                "path": "subfolder",
                "sha256":
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                "size": 0,
            },
        ],
        "symlinks": [],
    }
    test_dir = os.path.dirname(os.path.abspath(__file__))
    path = os.path.join(test_dir, "data", "repo")
    files_to_remove = [os.path.join(path, "a")]
    assert get_files_to_remove(dci_files_list, path) == files_to_remove
Exemplo n.º 3
0
def clean_download_folder(files_list, download_folder):
    if not os.path.isdir(download_folder):
        mkdir_p(download_folder)

    for file in get_files_to_remove(files_list, download_folder):
        print("Remove file %s" % file)
        os.remove(file)

    delete_all_symlink_in_path(download_folder)