Revert "Run Fuchsia apps without flx" (flutter/engine#4545)
* Revert "include portable_unistd.h in directory_asset_bundle (#4542)" This reverts commita41471bdd6. * Revert "Run Fuchsia apps without flx (#4538)" This reverts commit9bf76142c1.
This commit is contained in:
@@ -23,49 +23,15 @@ namespace blink {
|
||||
bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name,
|
||||
std::vector<uint8_t>* data) {
|
||||
std::string asset_path = GetPathForAsset(asset_name);
|
||||
|
||||
if (asset_path.empty())
|
||||
return false;
|
||||
|
||||
if (fd_.is_valid()) {
|
||||
fxl::UniqueFD asset_file(openat(fd_.get(), asset_path.c_str(), O_RDONLY));
|
||||
if (!asset_file.is_valid()) {
|
||||
FXL_LOG(ERROR) << "Could not load asset " << asset_name << " from "
|
||||
<< asset_path;
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr size_t kBufferSize = 1 << 16;
|
||||
size_t offset = 0;
|
||||
ssize_t bytes_read = 0;
|
||||
do {
|
||||
offset += bytes_read;
|
||||
data->resize(offset + kBufferSize);
|
||||
bytes_read = read(asset_file.get(), &(*data)[offset], kBufferSize);
|
||||
} while (bytes_read > 0);
|
||||
|
||||
if (bytes_read < 0) {
|
||||
FXL_LOG(ERROR) << "Reading " << asset_name << " failed";
|
||||
data->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
data->resize(offset + bytes_read);
|
||||
return true;
|
||||
}
|
||||
|
||||
return files::ReadFileToVector(asset_path, data);
|
||||
}
|
||||
|
||||
DirectoryAssetBundle::~DirectoryAssetBundle() {}
|
||||
|
||||
DirectoryAssetBundle::DirectoryAssetBundle(std::string directory)
|
||||
: directory_(std::move(directory)),
|
||||
fd_(fxl::internal::UniqueFDTraits::InvalidValue()) {}
|
||||
|
||||
DirectoryAssetBundle::DirectoryAssetBundle(fxl::UniqueFD fd,
|
||||
std::string directory)
|
||||
: directory_(std::move(directory)), fd_(std::move(fd)) {}
|
||||
: directory_(std::move(directory)) {}
|
||||
|
||||
std::string DirectoryAssetBundle::GetPathForAsset(
|
||||
const std::string& asset_name) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "lib/fxl/files/unique_fd.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
|
||||
@@ -18,8 +17,6 @@ class DirectoryAssetBundle
|
||||
: public fxl::RefCountedThreadSafe<DirectoryAssetBundle> {
|
||||
public:
|
||||
explicit DirectoryAssetBundle(std::string directory);
|
||||
// Expects fd to be valid, otherwise the file descriptor is ignored.
|
||||
explicit DirectoryAssetBundle(fxl::UniqueFD fd, std::string directory);
|
||||
~DirectoryAssetBundle();
|
||||
|
||||
bool GetAsBuffer(const std::string& asset_name, std::vector<uint8_t>* data);
|
||||
@@ -28,7 +25,6 @@ class DirectoryAssetBundle
|
||||
|
||||
private:
|
||||
const std::string directory_;
|
||||
fxl::UniqueFD fd_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user