Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a91e50bb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "[zip] Change const char* to string_view in ZipWriter"

parents 4a8d436a 2b283118
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "android-base/macros.h"
@@ -101,7 +102,7 @@ class ZipWriter {
   * Subsequent calls to WriteBytes(const void*, size_t) will add data to this entry.
   * Returns 0 on success, and an error value < 0 on failure.
   */
  int32_t StartEntry(const char* path, size_t flags);
  int32_t StartEntry(std::string_view path, size_t flags);

  /**
   * Starts a new zip entry with the given path and flags, where the
@@ -111,17 +112,17 @@ class ZipWriter {
   * Subsequent calls to WriteBytes(const void*, size_t) will add data to this entry.
   * Returns 0 on success, and an error value < 0 on failure.
   */
  int32_t StartAlignedEntry(const char* path, size_t flags, uint32_t alignment);
  int32_t StartAlignedEntry(std::string_view path, size_t flags, uint32_t alignment);

  /**
   * Same as StartEntry(const char*, size_t), but sets a last modified time for the entry.
   */
  int32_t StartEntryWithTime(const char* path, size_t flags, time_t time);
  int32_t StartEntryWithTime(std::string_view path, size_t flags, time_t time);

  /**
   * Same as StartAlignedEntry(const char*, size_t), but sets a last modified time for the entry.
   */
  int32_t StartAlignedEntryWithTime(const char* path, size_t flags, time_t time, uint32_t alignment);
  int32_t StartAlignedEntryWithTime(std::string_view path, size_t flags, time_t time, uint32_t alignment);

  /**
   * Writes bytes to the zip file for the previously started zip entry.
+5 −5
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ int32_t ZipWriter::HandleError(int32_t error_code) {
  return error_code;
}

int32_t ZipWriter::StartEntry(const char* path, size_t flags) {
int32_t ZipWriter::StartEntry(std::string_view path, size_t flags) {
  uint32_t alignment = 0;
  if (flags & kAlign32) {
    flags &= ~kAlign32;
@@ -139,11 +139,11 @@ int32_t ZipWriter::StartEntry(const char* path, size_t flags) {
  return StartAlignedEntryWithTime(path, flags, time_t(), alignment);
}

int32_t ZipWriter::StartAlignedEntry(const char* path, size_t flags, uint32_t alignment) {
int32_t ZipWriter::StartAlignedEntry(std::string_view path, size_t flags, uint32_t alignment) {
  return StartAlignedEntryWithTime(path, flags, time_t(), alignment);
}

int32_t ZipWriter::StartEntryWithTime(const char* path, size_t flags, time_t time) {
int32_t ZipWriter::StartEntryWithTime(std::string_view path, size_t flags, time_t time) {
  uint32_t alignment = 0;
  if (flags & kAlign32) {
    flags &= ~kAlign32;
@@ -198,7 +198,7 @@ static void CopyFromFileEntry(const ZipWriter::FileEntry& src, bool use_data_des
  dst->extra_field_length = src.padding_length;
}

int32_t ZipWriter::StartAlignedEntryWithTime(const char* path, size_t flags, time_t time,
int32_t ZipWriter::StartAlignedEntryWithTime(std::string_view path, size_t flags, time_t time,
                                             uint32_t alignment) {
  if (state_ != State::kWritingZip) {
    return kInvalidState;
@@ -265,7 +265,7 @@ int32_t ZipWriter::StartAlignedEntryWithTime(const char* path, size_t flags, tim
    return HandleError(kIoError);
  }

  if (fwrite(path, sizeof(*path), file_entry.path.size(), file_) != file_entry.path.size()) {
  if (fwrite(path.data(), 1, path.size(), file_) != path.size()) {
    return HandleError(kIoError);
  }