Optimize read to only read the hierarchy once

This commit is contained in:
Baptiste Wicht 2013-12-26 17:25:17 +01:00
parent 6e7f1b588d
commit b6337900af

View File

@ -495,6 +495,8 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti
return {};
}
uint32_t cluster_number;
size_t file_size = 0;
auto found = false;
auto all_files = files(disk, path);
@ -502,6 +504,7 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti
if(f.file_name == file){
found = true;
file_size = f.size;
cluster_number = f.location;
break;
}
}
@ -510,20 +513,6 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti
return {};
}
std::vector<std::string> complete_path;
for(auto& p : path){
complete_path.push_back(p);
}
complete_path.push_back(file);
auto cluster_number_search = find_cluster_number(disk, complete_path);
if(!cluster_number_search.first){
return {};
}
auto cluster_number = cluster_number_search.second;
std::string content(file_size + 1);
size_t read = 0;