Keep archive's file opened in the archive's whole life time
This commit is contained in:
parent
f02cae1b0a
commit
f8e1dfbbc6
4 changed files with 15 additions and 10 deletions
|
@ -104,6 +104,7 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
|
|||
|
||||
Archive::Archive(const base::FilePath& path)
|
||||
: path_(path),
|
||||
file_(path_, base::File::FLAG_OPEN | base::File::FLAG_READ),
|
||||
header_size_(0) {
|
||||
}
|
||||
|
||||
|
@ -111,15 +112,14 @@ Archive::~Archive() {
|
|||
}
|
||||
|
||||
bool Archive::Init() {
|
||||
base::File file(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
||||
if (!file.IsValid())
|
||||
if (!file_.IsValid())
|
||||
return false;
|
||||
|
||||
std::vector<char> buf;
|
||||
int len;
|
||||
|
||||
buf.resize(8);
|
||||
len = file.ReadAtCurrentPos(buf.data(), buf.size());
|
||||
len = file_.ReadAtCurrentPos(buf.data(), buf.size());
|
||||
if (len != static_cast<int>(buf.size())) {
|
||||
PLOG(ERROR) << "Failed to read header size from " << path_.value();
|
||||
return false;
|
||||
|
@ -132,7 +132,7 @@ bool Archive::Init() {
|
|||
}
|
||||
|
||||
buf.resize(size);
|
||||
len = file.ReadAtCurrentPos(buf.data(), buf.size());
|
||||
len = file_.ReadAtCurrentPos(buf.data(), buf.size());
|
||||
if (len != static_cast<int>(buf.size())) {
|
||||
PLOG(ERROR) << "Failed to read header from " << path_.value();
|
||||
return false;
|
||||
|
@ -250,7 +250,7 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
|
|||
}
|
||||
|
||||
scoped_ptr<ScopedTemporaryFile> temp_file(new ScopedTemporaryFile);
|
||||
if (!temp_file->InitFromFile(path_, info.offset, info.size))
|
||||
if (!temp_file->InitFromFile(file_, info.offset, info.size))
|
||||
return false;
|
||||
|
||||
*out = temp_file->path();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue