-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirmware_file.cc
54 lines (41 loc) · 1.62 KB
/
firmware_file.cc
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
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "modemfwd/firmware_file.h"
#include <base/logging.h>
#include "modemfwd/file_decompressor.h"
namespace modemfwd {
FirmwareFile::FirmwareFile() = default;
FirmwareFile::~FirmwareFile() = default;
bool FirmwareFile::PrepareFrom(const FirmwareFileInfo& file_info) {
switch (file_info.compression) {
case FirmwareFileInfo::Compression::NONE:
path_for_logging_ = file_info.firmware_path;
path_on_filesystem_ = file_info.firmware_path;
return true;
case FirmwareFileInfo::Compression::XZ: {
// A xz-compressed firmware file should end with a .xz extension.
CHECK_EQ(file_info.firmware_path.FinalExtension(), ".xz");
if (!temp_dir_.CreateUniqueTempDir()) {
LOG(ERROR) << "Failed to create temporary directory for "
"decompressing firmware";
return false;
}
// Maintains the original firmware file name with the trailing .xz
// extension removed.
base::FilePath actual_path = temp_dir_.GetPath().Append(
file_info.firmware_path.BaseName().RemoveFinalExtension());
if (!DecompressXzFile(file_info.firmware_path, actual_path)) {
LOG(ERROR) << "Failed to decompress firmware: "
<< file_info.firmware_path.value();
return false;
}
path_for_logging_ = file_info.firmware_path;
path_on_filesystem_ = actual_path;
return true;
}
}
NOTREACHED();
return false;
}
} // namespace modemfwd