def test_create_info_files_json_no_inodes(testing_workdir, testing_metadata): info_dir = os.path.join(testing_workdir, "info") os.mkdir(info_dir) path_one = os.path.join(testing_workdir, "one") path_two = os.path.join(testing_workdir, "two") path_foo = os.path.join(testing_workdir, "foo") path_one_hardlink = os.path.join(testing_workdir, "one_hl") open(path_one, "a").close() open(path_two, "a").close() open(path_foo, "a").close() os.link(path_one, path_one_hardlink) files_with_prefix = [("prefix/path", "text", "foo")] files = ["one", "two", "one_hl", "foo"] build.create_info_files_json_v1(testing_metadata, info_dir, testing_workdir, files, files_with_prefix) files_json_path = os.path.join(info_dir, "paths.json") expected_output = { "paths": [{"file_mode": "text", "path_type": "hardlink", "_path": "foo", "prefix_placeholder": "prefix/path", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}, {"path_type": "hardlink", "_path": "one", "inode_paths": ["one", "one_hl"], "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}, {"path_type": "hardlink", "_path": "one_hl", "inode_paths": ["one", "one_hl"], "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}, {"path_type": "hardlink", "_path": "two", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}], "paths_version": 1} with open(files_json_path, "r") as files_json: output = json.load(files_json) assert output == expected_output
def test_create_info_files_json_no_inodes(testing_workdir, testing_metadata): info_dir = os.path.join(testing_workdir, "info") os.mkdir(info_dir) path_one = os.path.join(testing_workdir, "one") path_two = os.path.join(testing_workdir, "two") path_foo = os.path.join(testing_workdir, "foo") path_one_hardlink = os.path.join(testing_workdir, "one_hl") open(path_one, "a").close() open(path_two, "a").close() open(path_foo, "a").close() os.link(path_one, path_one_hardlink) files_with_prefix = [("prefix/path", "text", "foo")] files = ["one", "two", "one_hl", "foo"] build.create_info_files_json_v1(testing_metadata, info_dir, testing_workdir, files, files_with_prefix) files_json_path = os.path.join(info_dir, "paths.json") expected_output = { "paths": [{"file_mode": "text", "path_type": "hardlink", "_path": "foo", "prefix_placeholder": "prefix/path", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}, {"path_type": "hardlink", "_path": "one", "inode_paths": ["one", "one_hl"], "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}, {"path_type": "hardlink", "_path": "one_hl", "inode_paths": ["one", "one_hl"], "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}, {"path_type": "hardlink", "_path": "two", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0}], "paths_version": 1} with open(files_json_path, "r") as files_json: output = json.load(files_json) assert output == expected_output
def create_info_files(m, files, prefix): """ Creates the metadata files that will be stored in the built package. :param m: Package metadata :type m: Metadata :param files: Paths to files to include in package :type files: list of str """ if utils.on_win: # make sure we use '/' path separators in metadata files = [_f.replace("\\", "/") for _f in files] if m.config.filename_hashing: write_hash_input(m) write_info_json(m) # actually index.json write_about_json(m) write_link_json(m) write_run_exports(m) # TODO copy_recipe(m) copy_readme(m) copy_license(m) copy_recipe_log(m) # files.extend(jsonify_info_yamls(m)) create_all_test_files(m, test_dir=join(m.config.info_dir, "test")) if m.config.copy_test_source_files: copy_test_source_files(m, join(m.config.info_dir, "test")) write_info_files_file(m, files) files_with_prefix = get_files_with_prefix(m, [], files, prefix) record_prefix_files(m, files_with_prefix) checksums = create_info_files_json_v1(m, m.config.info_dir, prefix, files, files_with_prefix) # write_no_link(m, files) sources = m.get_section("source") if hasattr(sources, "keys"): sources = [sources] with io.open(join(m.config.info_dir, "git"), "w", encoding="utf-8") as fo: for src in sources: if src.get("git_url"): source.git_info( os.path.join(m.config.work_dir, src.get("folder", "")), build_prefix=m.config.build_prefix, verbose=m.config.verbose, fo=fo, ) if m.get_value("app/icon"): utils.copy_into( join(m.path, m.get_value("app/icon")), join(m.config.info_dir, "icon.png"), m.config.timeout, locking=m.config.locking, ) return checksums
def test_create_info_files_json_symlinks(testing_workdir, testing_metadata): info_dir = os.path.join(testing_workdir, "info") os.mkdir(info_dir) path_one = os.path.join(testing_workdir, "one") path_two = os.path.join(testing_workdir, "two") path_three = os.path.join(testing_workdir, "three") # do not make this one path_foo = os.path.join(testing_workdir, "foo") path_two_symlink = os.path.join(testing_workdir, "two_sl") symlink_to_nowhere = os.path.join(testing_workdir, "nowhere_sl") recursive_symlink = os.path.join(testing_workdir, "recursive_sl") cycle1_symlink = os.path.join(testing_workdir, "cycle1_sl") cycle2_symlink = os.path.join(testing_workdir, "cycle2_sl") open(path_one, "a").close() open(path_two, "a").close() open(path_foo, "a").close() os.symlink(path_two, path_two_symlink) os.symlink(path_three, symlink_to_nowhere) # make some recursive links os.symlink(path_two_symlink, recursive_symlink) os.symlink(cycle1_symlink, cycle2_symlink) os.symlink(cycle2_symlink, cycle1_symlink) files_with_prefix = [("prefix/path", "text", "foo")] files = [ "one", "two", "foo", "two_sl", "nowhere_sl", "recursive_sl", "cycle1_sl", "cycle2_sl" ] build.create_info_files_json_v1(testing_metadata, info_dir, testing_workdir, files, files_with_prefix) files_json_path = os.path.join(info_dir, "paths.json") expected_output = { "paths": [{ "path_type": "softlink", "_path": "cycle1_sl", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "path_type": "softlink", "_path": "cycle2_sl", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "file_mode": "text", "path_type": "hardlink", "_path": "foo", "prefix_placeholder": "prefix/path", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "path_type": "softlink", "_path": "nowhere_sl", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "path_type": "hardlink", "_path": "one", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "path_type": "softlink", "_path": "recursive_sl", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "path_type": "hardlink", "_path": "two", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, { "path_type": "softlink", "_path": "two_sl", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }], "paths_version": 1 } with open(files_json_path) as files_json: output = json.load(files_json) assert output == expected_output