fixup hdd1 cache

This commit is contained in:
Eladash 2024-01-15 10:54:11 +02:00 committed by Elad.Ash
parent 9c354ee269
commit e4c9af176b
3 changed files with 71 additions and 18 deletions

View file

@ -232,6 +232,9 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
const TARHeader& header = iter->second.second;
const std::string& name = iter->first;
// Backwards compatibility measure
const bool should_ignore = name.find(reinterpret_cast<const char*>(u8"")) != umax;
std::string result = name;
if (!prefix_path.empty())
@ -291,7 +294,16 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
std::unique_ptr<utils::serial> file_data = get_file(name);
fs::file file(result, fs::rewrite);
fs::file file;
if (should_ignore)
{
file = fs::make_stream<std::vector<u8>>();
}
else
{
file.open(result, fs::rewrite);
}
if (file && file_data)
{
@ -301,7 +313,7 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
if (unread_size == 0)
{
file.write(filedata_span.data(), filedata_span.size());
file.write(filedata_span.data(), should_ignore ? 0 : filedata_span.size());
continue;
}
@ -310,7 +322,7 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
if (usz read_size = filedata_span.size() - unread_size)
{
ensure(file_data->try_read(filedata_span.first(read_size)) == 0);
file.write(filedata_span.data(), read_size);
file.write(filedata_span.data(), should_ignore ? 0 : read_size);
}
break;
@ -318,6 +330,7 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
file.close();
file_data->seek_pos(m_ar_tar_start + largest_offset, true);
if (!m_file)
@ -327,6 +340,11 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
m_ar->m_max_data = restore_limit;
}
if (should_ignore)
{
break;
}
if (mtime != umax && !fs::utime(result, atime, mtime))
{
tar_log.error("TAR Loader: fs::utime failed on %s (%s)", result, fs::g_tls_error);
@ -351,6 +369,11 @@ bool tar_object::extract(std::string prefix_path, bool is_vfs)
case '5':
{
if (should_ignore)
{
break;
}
if (!fs::create_path(result))
{
tar_log.error("TAR Loader: failed to create directory %s (%s)", name, fs::g_tls_error);
@ -576,7 +599,7 @@ void tar_object::save_directory(const std::string& target_path, utils::serial& a
{
exists = true;
if (entry.name.find_first_not_of('.') == umax)
if (entry.name.find_first_not_of('.') == umax || entry.name.starts_with(reinterpret_cast<const char*>(u8"")))
{
continue;
}