dataloader/incfs openWrite returns int

Plus minor refactors

Test: atest PackageManagerShellCommandIncrementalTest
Change-Id: Ib3a1c7c45a4abaab793be73213545ce91c98510b
This commit is contained in:
Songchun Fan
2020-02-26 11:02:37 -08:00
parent 146f416895
commit 9b30727de8
3 changed files with 15 additions and 14 deletions

View File

@@ -101,8 +101,7 @@ public final class IncrementalFileStorages {
} catch (IOException e) {
// TODO(b/146080380): add incremental-specific error code
throw new IOException(
"Failed to add file to IncFS: " + file.getName() + ", reason: "
+ e.getMessage(), e.getCause());
"Failed to add file to IncFS: " + file.getName() + ", reason: ", e);
}
} else {
throw new IOException("Unknown file location: " + file.getLocation());
@@ -117,6 +116,7 @@ public final class IncrementalFileStorages {
return result;
} catch (IOException e) {
Slog.e(TAG, "Failed to initialize Incremental file storages. Cleaning up...", e);
if (result != null) {
result.cleanUp();
}

View File

@@ -424,14 +424,18 @@ public final class IncrementalStorage {
*/
private static IncrementalSignature parseV4Signature(@Nullable byte[] v4signatureBytes)
throws IOException {
if (v4signatureBytes == null) {
if (v4signatureBytes == null || v4signatureBytes.length == 0) {
return null;
}
final V4Signature signature;
try (DataInputStream input = new DataInputStream(
new ByteArrayInputStream(v4signatureBytes))) {
signature = V4Signature.readFrom(input);
try {
signature = V4Signature.readFrom(input);
} catch (IOException e) {
throw new IOException("Failed to read v4 signature:", e);
}
}
if (!signature.isVersionSupported()) {

View File

@@ -16,22 +16,17 @@
#define ATRACE_TAG ATRACE_TAG_ADB
#define LOG_TAG "PackageManagerShellCommandDataLoader-jni"
#include <android-base/logging.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <core_jni_helpers.h>
#include <cutils/trace.h>
#include <endian.h>
#include <nativehelper/JNIHelp.h>
#include <sys/eventfd.h>
#include <sys/poll.h>
#include <nativehelper/JNIHelp.h>
#include <core_jni_helpers.h>
#include <endian.h>
#include "dataloader.h"
#include <charconv>
#include <chrono>
#include <span>
@@ -40,6 +35,8 @@
#include <unordered_map>
#include <unordered_set>
#include "dataloader.h"
namespace android {
namespace {
@@ -681,7 +678,7 @@ private:
auto& writeFd = writeFds[fileIdx];
if (writeFd < 0) {
writeFd = this->mIfs->openWrite(fileId);
writeFd.reset(this->mIfs->openWrite(fileId));
if (writeFd < 0) {
ALOGE("Failed to open file %d for writing (%d). Aboring.", header.fileIdx,
-writeFd);