Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Read the path and hashPath properties when reading .deps.json in hostfxr/policy #247

Merged
merged 5 commits into from Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 50 additions & 17 deletions src/corehost/cli/deps_entry.cpp
Expand Up @@ -118,8 +118,16 @@ bool deps_entry_t::to_full_path(const pal::string_t& base, pal::string_t* str) c
}

pal::string_t new_base = base;
append_path(&new_base, library_name.c_str());
append_path(&new_base, library_version.c_str());

if (library_path.empty())
{
append_path(&new_base, library_name.c_str());
append_path(&new_base, library_version.c_str());
}
else
{
append_path(&new_base, library_path.c_str());
}

return to_rel_path(new_base, str);
}
Expand Down Expand Up @@ -164,24 +172,49 @@ bool deps_entry_t::to_hash_matched_path(const pal::string_t& base, pal::string_t
trace::verbose(_X("Invalid hash %s value for deps file entry: %s"), library_hash.c_str(), library_name.c_str());
return false;
}

// Build the relative hash path (what is added to the package directory path).
pal::string_t relative_hash_path;
if (library_hash_path.empty())
{
// Reserve approx 8 char_t's for the algorithm name.
relative_hash_path.reserve(library_name.length() + 1 + library_version.length() + 16);
relative_hash_path.append(library_name);
relative_hash_path.append(_X("."));
relative_hash_path.append(library_version);
relative_hash_path.append(_X(".nupkg."));
relative_hash_path.append(library_hash.substr(0, pos));
}
else
{
relative_hash_path.assign(library_hash_path);
}

// Build the nupkg file name. Just reserve approx 8 char_t's for the algorithm name.
pal::string_t nupkg_filename;
nupkg_filename.reserve(library_name.length() + 1 + library_version.length() + 16);
nupkg_filename.append(library_name);
nupkg_filename.append(_X("."));
nupkg_filename.append(library_version);
nupkg_filename.append(_X(".nupkg."));
nupkg_filename.append(library_hash.substr(0, pos));

// Build the hash file path str.
// Build the directory that contains the hash file.
pal::string_t hash_file;
hash_file.reserve(base.length() + library_name.length() + library_version.length() + nupkg_filename.length() + 3);
hash_file.assign(base);
append_path(&hash_file, library_name.c_str());
append_path(&hash_file, library_version.c_str());
append_path(&hash_file, nupkg_filename.c_str());
if (library_path.empty())

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

{
hash_file.reserve(base.length() + 1 +
library_name.length() + 1 + library_version.length() + 1 +
relative_hash_path.length());
hash_file.assign(base);

append_path(&hash_file, library_name.c_str());
append_path(&hash_file, library_version.c_str());
}
else
{
hash_file.reserve(base.length() + 1 +
library_path.length() + 1 +
relative_hash_path.length());
hash_file.assign(base);

append_path(&hash_file, library_path.c_str());
}

// Append the relative path to the hash file.
append_path(&hash_file, relative_hash_path.c_str());

// Read the contents of the hash file.
pal::ifstream_t fstream(hash_file);
if (!fstream.good())
Expand Down
2 changes: 2 additions & 0 deletions src/corehost/cli/deps_entry.h
Expand Up @@ -25,6 +25,8 @@ struct deps_entry_t
pal::string_t library_name;
pal::string_t library_version;
pal::string_t library_hash;
pal::string_t library_path;
pal::string_t library_hash_path;
asset_types asset_type;
pal::string_t asset_name;
pal::string_t relative_path;
Expand Down
28 changes: 27 additions & 1 deletion src/corehost/cli/deps_format.cpp
Expand Up @@ -25,6 +25,27 @@ const deps_entry_t& deps_json_t::try_ni(const deps_entry_t& entry) const
return entry;
}

pal::string_t deps_json_t::get_optional_path(
const json_object& properties,
const pal::string_t& key) const
{
pal::string_t path;

const auto& iter = properties.find(key);

if (iter != properties.end())
{
path = iter->second.as_string();

if (_X('/') != DIR_SEPARATOR)
{
replace_char(&path, _X('/'), DIR_SEPARATOR);
}
}

return path;
}

void deps_json_t::reconcile_libraries_with_targets(
const json_value& json,
const std::function<bool(const pal::string_t&)>& library_exists_fn,
Expand All @@ -46,6 +67,9 @@ void deps_json_t::reconcile_libraries_with_targets(
const pal::string_t& hash = properties.at(_X("sha512")).as_string();
bool serviceable = properties.at(_X("serviceable")).as_bool();

pal::string_t library_path = get_optional_path(properties, _X("path"));
pal::string_t library_hash_path = get_optional_path(properties, _X("hashPath"));

for (int i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
{
bool rid_specific = false;
Expand All @@ -63,8 +87,10 @@ void deps_json_t::reconcile_libraries_with_targets(
size_t pos = library.first.find(_X("/"));
entry.library_name = library.first.substr(0, pos);
entry.library_version = library.first.substr(pos + 1);
entry.library_type = pal::to_lower(library.second.at(_X("type")).as_string());
entry.library_type = pal::to_lower(properties.at(_X("type")).as_string());
entry.library_hash = hash;
entry.library_path = library_path;
entry.library_hash_path = library_hash_path;
entry.asset_name = asset_name;
entry.asset_type = (deps_entry_t::asset_types) i;
entry.relative_path = rel_path;
Expand Down
3 changes: 3 additions & 0 deletions src/corehost/cli/deps_format.h
Expand Up @@ -15,6 +15,7 @@
class deps_json_t
{
typedef web::json::value json_value;
typedef web::json::object json_object;
struct vec_t { std::vector<pal::string_t> vec; };
struct assets_t { std::array<vec_t, deps_entry_t::asset_types::count> by_type; };
struct deps_assets_t { std::unordered_map<pal::string_t, assets_t> libs; };
Expand Down Expand Up @@ -80,6 +81,8 @@ class deps_json_t
const std::function<bool(const pal::string_t&)>& library_exists_fn,
const std::function<const std::vector<pal::string_t>&(const pal::string_t&, int, bool*)>& get_rel_paths_by_asset_type_fn);

pal::string_t get_optional_path(const json_object& properties, const pal::string_t& key) const;

bool perform_rid_fallback(rid_specific_assets_t* portable_assets, const rid_fallback_graph_t& rid_fallback_graph);

std::vector<deps_entry_t> m_deps_entries[deps_entry_t::asset_types::count];
Expand Down