forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_entry.cpp
More file actions
65 lines (51 loc) · 1.77 KB
/
file_entry.cpp
File metadata and controls
65 lines (51 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "file_entry.h"
#include "trace.h"
#include "dir_utils.h"
#include "error_codes.h"
using namespace bundle;
bool file_entry_t::is_valid() const
{
return m_offset > 0 && m_size >= 0 && m_compressedSize >= 0 &&
static_cast<file_type_t>(m_type) < file_type_t::__last;
}
file_entry_t file_entry_t::read(reader_t &reader, uint32_t bundle_major_version, bool force_extraction)
{
// First read the fixed-sized portion of file-entry
file_entry_fixed_t fixed_data;
// NB: the file data is potentially unaligned, thus we use "read" to fetch 64bit values
reader.read(&fixed_data.offset, sizeof(int64_t));
reader.read(&fixed_data.size, sizeof(int64_t));
// compressedSize is present only in v6+ headers
fixed_data.compressedSize = 0;
if (bundle_major_version >= 6)
{
reader.read(&fixed_data.compressedSize, sizeof(int64_t));
}
fixed_data.type = (file_type_t)reader.read_byte();
file_entry_t entry(&fixed_data, force_extraction);
if (!entry.is_valid())
{
trace::error(_X("Failure processing application bundle; possible file corruption."));
trace::error(_X("Invalid FileEntry detected."));
throw StatusCode::BundleExtractionFailure;
}
reader.read_path_string(entry.m_relative_path);
dir_utils_t::fixup_path_separator(entry.m_relative_path);
return entry;
}
bool file_entry_t::needs_extraction() const
{
if (m_force_extraction)
return true;
switch (m_type)
{
case file_type_t::deps_json:
case file_type_t::runtime_config_json:
case file_type_t::assembly:
return false;
default:
return true;
}
}