forked from chenxiaolong/DualBootPatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libmbpatcher: Fix incorrect add_file() overload being called
Signed-off-by: Andrew Gunnerson <[email protected]>
- Loading branch information
1 parent
d7def58
commit 81fccc0
Showing
7 changed files
with
42 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2014-2016 Andrew Gunnerson <[email protected]> | ||
* Copyright (C) 2014-2018 Andrew Gunnerson <[email protected]> | ||
* | ||
* This file is part of DualBootPatcher | ||
* | ||
|
@@ -20,7 +20,6 @@ | |
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "mbcommon/file/standard.h" | ||
|
||
|
@@ -37,13 +36,9 @@ class FileUtils | |
const std::string &path, | ||
FileOpenMode mode); | ||
|
||
static ErrorCode read_to_memory(const std::string &path, | ||
std::vector<unsigned char> *contents); | ||
static ErrorCode read_to_string(const std::string &path, | ||
std::string *contents); | ||
|
||
static ErrorCode write_from_memory(const std::string &path, | ||
const std::vector<unsigned char> &contents); | ||
static ErrorCode write_from_string(const std::string &path, | ||
const std::string &contents); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2014-2017 Andrew Gunnerson <[email protected]> | ||
* Copyright (C) 2014-2018 Andrew Gunnerson <[email protected]> | ||
* | ||
* This file is part of DualBootPatcher | ||
* | ||
|
@@ -60,53 +60,6 @@ oc::result<void> FileUtils::open_file(StandardFile &file, | |
#endif | ||
} | ||
|
||
/*! | ||
* \brief Read contents of a file into memory | ||
* | ||
* \param path Path to file | ||
* \param contents Output vector (not modified unless reading succeeds) | ||
* | ||
* \return Success or not | ||
*/ | ||
ErrorCode FileUtils::read_to_memory(const std::string &path, | ||
std::vector<unsigned char> *contents) | ||
{ | ||
StandardFile file; | ||
|
||
auto ret = open_file(file, path, FileOpenMode::ReadOnly); | ||
if (!ret) { | ||
LOGE("%s: Failed to open for reading: %s", | ||
path.c_str(), ret.error().message().c_str()); | ||
return ErrorCode::FileOpenError; | ||
} | ||
|
||
auto size = file.seek(0, SEEK_END); | ||
if (!size) { | ||
LOGE("%s: Failed to seek file: %s", | ||
path.c_str(), size.error().message().c_str()); | ||
return ErrorCode::FileSeekError; | ||
} | ||
auto seek_ret = file.seek(0, SEEK_SET); | ||
if (!seek_ret) { | ||
LOGE("%s: Failed to seek file: %s", | ||
path.c_str(), seek_ret.error().message().c_str()); | ||
return ErrorCode::FileSeekError; | ||
} | ||
|
||
std::vector<unsigned char> data(static_cast<size_t>(size.value())); | ||
|
||
auto bytes_read = file.read(data.data(), data.size()); | ||
if (!bytes_read || bytes_read.value() != size.value()) { | ||
LOGE("%s: Failed to read file: %s", | ||
path.c_str(), bytes_read.error().message().c_str()); | ||
return ErrorCode::FileReadError; | ||
} | ||
|
||
data.swap(*contents); | ||
|
||
return ErrorCode::NoError; | ||
} | ||
|
||
/*! | ||
* \brief Read contents of a file into a string | ||
* | ||
|
@@ -155,28 +108,6 @@ ErrorCode FileUtils::read_to_string(const std::string &path, | |
return ErrorCode::NoError; | ||
} | ||
|
||
ErrorCode FileUtils::write_from_memory(const std::string &path, | ||
const std::vector<unsigned char> &contents) | ||
{ | ||
StandardFile file; | ||
|
||
auto ret = open_file(file, path, FileOpenMode::WriteOnly); | ||
if (!ret) { | ||
LOGE("%s: Failed to open for writing: %s", | ||
path.c_str(), ret.error().message().c_str()); | ||
return ErrorCode::FileOpenError; | ||
} | ||
|
||
auto bytes_written = file.write(contents.data(), contents.size()); | ||
if (!bytes_written || bytes_written.value() != contents.size()) { | ||
LOGE("%s: Failed to write file: %s", | ||
path.c_str(), bytes_written.error().message().c_str()); | ||
return ErrorCode::FileWriteError; | ||
} | ||
|
||
return ErrorCode::NoError; | ||
} | ||
|
||
ErrorCode FileUtils::write_from_string(const std::string &path, | ||
const std::string &contents) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters