Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #699: Add support to unzip from a string representation #928

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cobalt/updater/unzipper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "cobalt/updater/unzipper.h"

#include <string>
#include <utility>

#include "base/callback.h"
#include "base/files/file_path.h"
#include "starboard/time.h"
Expand All @@ -40,6 +42,20 @@ class UnzipperImpl : public update_client::Unzipper {
LOG(INFO) << "Unzip took " << time_unzip_took / kSbTimeMillisecond
<< " milliseconds.";
}

#if defined(IN_MEMORY_UPDATES)
void Unzip(const std::string& zip_str, const base::FilePath& output_path,
UnzipCompleteCallback callback) override {
SbTimeMonotonic time_before_unzip = SbTimeGetMonotonicNow();
std::move(callback).Run(zip::Unzip(zip_str, output_path));
SbTimeMonotonic time_unzip_took =
SbTimeGetMonotonicNow() - time_before_unzip;
LOG(INFO) << "Unzip from string";
LOG(INFO) << "output_path = " << output_path;
LOG(INFO) << "Unzip took " << time_unzip_took / kSbTimeMillisecond
<< " milliseconds.";
}
#endif
};

} // namespace
Expand Down
7 changes: 7 additions & 0 deletions components/update_client/unzip/unzip_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class UnzipperImpl : public Unzipper {
UnzipCompleteCallback callback) override {
unzip::Unzip(callback_.Run(), zip_file, destination, std::move(callback));
}
#if defined(IN_MEMORY_UPDATES)
void Unzip(const std::string& zip_str,
const base::FilePath& destination,
UnzipCompleteCallback callback) override {
unzip::Unzip(callback_.Run(), zip_str, destination, std::move(callback));
}
#endif

private:
const UnzipChromiumFactory::Callback callback_;
Expand Down
11 changes: 10 additions & 1 deletion components/update_client/unzip/unzip_impl_cobalt.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Copyright 2019 The Cobalt 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 "components/update_client/unzip/unzip_impl_cobalt.h"

#include <string>
#include <utility>

#include "base/callback.h"
#include "base/files/file_path.h"
#include "starboard/time.h"
Expand All @@ -23,6 +25,13 @@ class UnzipperImpl : public update_client::Unzipper {
UnzipCompleteCallback callback) override {
std::move(callback).Run(zip::Unzip(zip_path, output_path));
}
#if defined(IN_MEMORY_UPDATES)
void Unzip(const std::string& zip_str,
const base::FilePath& output_path,
UnzipCompleteCallback callback) override {
std::move(callback).Run(zip::Unzip(zip_str, output_path));
}
#endif
};

} // namespace
Expand Down
6 changes: 6 additions & 0 deletions components/update_client/unzipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class Unzipper {
const base::FilePath& destination,
UnzipCompleteCallback callback) = 0;

#if defined(IN_MEMORY_UPDATES)
virtual void Unzip(const std::string& zip_str,
const base::FilePath& destination,
UnzipCompleteCallback callback) = 0;
#endif

protected:
Unzipper() = default;

Expand Down
11 changes: 11 additions & 0 deletions starboard/evergreen/shared/platform_configuration/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ config("platform_configuration") {
# By default, <EGL/eglplatform.h> pulls in some X11 headers that have some
# nasty macros (|Status|, for example) that conflict with Chromium base.
"MESA_EGL_NO_X11_HEADERS",

# During Evergreen updates the CRX package is kept in-memory, instead of
# on the file system, before getting unpacked.
# TODO(b/158043520): we need to make significant customizations to Chromium
# code to implement this feature and this macro allows us to switch back
# to the legacy behavior during development to verify the customizations
# are made cleanly. Once the feature is complete we may want to remove
# existing customizations that enable the legacy behavior for Cobalt builds,
# change IN_MEMORY_UPDATES references to USE_COBALT_CUSTOMIZATIONS
# references, and remove this macro.
"IN_MEMORY_UPDATES",
]

if (is_debug) {
Expand Down
67 changes: 59 additions & 8 deletions third_party/zlib/google/zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ bool Unzip(const base::FilePath& src_file, const base::FilePath& dest_dir) {
return UnzipWithFilterCallback(
src_file, dest_dir, base::BindRepeating(&ExcludeNoFilesFilter), true);
}
#if defined(IN_MEMORY_UPDATES)
bool Unzip(const std::string& src_str, const base::FilePath& dest_dir) {
return UnzipWithFilterCallback(
src_str, dest_dir, base::BindRepeating(&ExcludeNoFilesFilter), true);
}
#endif


bool UnzipWithFilterCallback(const base::FilePath& src_file,
const base::FilePath& dest_dir,
Expand All @@ -200,17 +207,24 @@ bool UnzipWithFilterCallback(const base::FilePath& src_file,
#endif
}

#if defined(IN_MEMORY_UPDATES)
bool UnzipWithFilterCallback(const std::string& src_str,
const base::FilePath& dest_dir,
const FilterCallback& filter_cb,
bool log_skipped_files) {
return UnzipWithFilterAndWriters(
src_str, base::BindRepeating(&CreateFilePathWriterDelegate, dest_dir),
base::BindRepeating(&CreateDirectory, dest_dir), filter_cb,
log_skipped_files);
}
#endif

#if defined(STARBOARD)
bool UnzipWithFilterAndWriters(const base::FilePath& src_file,
bool UnzipWithFilterAndWriters(ZipReader& reader,
const WriterFactory& writer_factory,
const DirectoryCreator& directory_creator,
const FilterCallback& filter_cb,
bool log_skipped_files) {
ZipReader reader;
if (!reader.Open(src_file)) {
DLOG(WARNING) << "Failed to open src_file " << src_file;
return false;
}
while (reader.HasMore()) {
if (!reader.OpenCurrentEntryInZip()) {
DLOG(WARNING) << "Failed to open the current file in zip";
Expand Down Expand Up @@ -244,7 +258,44 @@ bool UnzipWithFilterAndWriters(const base::FilePath& src_file,
}
return true;
}
#else

bool UnzipWithFilterAndWriters(const base::FilePath& src_file,
const WriterFactory& writer_factory,
const DirectoryCreator& directory_creator,
const FilterCallback& filter_cb,
bool log_skipped_files) {
ZipReader reader;
if (!reader.Open(src_file)) {
DLOG(WARNING) << "Failed to open src_file " << src_file;
return false;
}
return UnzipWithFilterAndWriters(reader,
writer_factory,
directory_creator,
filter_cb,
log_skipped_files);
}

#if defined(IN_MEMORY_UPDATES)
bool UnzipWithFilterAndWriters(const std::string& src_str,
const WriterFactory& writer_factory,
const DirectoryCreator& directory_creator,
const FilterCallback& filter_cb,
bool log_skipped_files) {
ZipReader reader;
if (!reader.OpenFromString(src_str)) {
DLOG(WARNING) << "Failed to open src_str";
return false;
}
return UnzipWithFilterAndWriters(reader,
writer_factory,
directory_creator,
filter_cb,
log_skipped_files);
}
#endif // defined(IN_MEMORY_UPDATES)
#else // defined(STARBOARD)

bool UnzipWithFilterAndWriters(const base::PlatformFile& src_file,
const WriterFactory& writer_factory,
const DirectoryCreator& directory_creator,
Expand Down Expand Up @@ -288,7 +339,7 @@ bool UnzipWithFilterAndWriters(const base::PlatformFile& src_file,
}
return true;
}
#endif
#endif // STARBOARD

bool ZipWithFilterCallback(const base::FilePath& src_dir,
const base::FilePath& dest_file,
Expand Down
24 changes: 22 additions & 2 deletions third_party/zlib/google/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ bool UnzipWithFilterCallback(const base::FilePath& zip_file,
const FilterCallback& filter_cb,
bool log_skipped_files);

#if defined(IN_MEMORY_UPDATES)
// An overload for a zip represented as a string.
bool UnzipWithFilterCallback(const std::string& zip_str,
const base::FilePath& dest_dir,
const FilterCallback& filter_cb,
bool log_skipped_files);
#endif

// Unzip the contents of zip_file, using the writers provided by writer_factory.
// For each file in zip_file, include it only if the callback |filter_cb|
// returns true. Otherwise omit it.
Expand All @@ -174,16 +182,28 @@ bool UnzipWithFilterAndWriters(const base::FilePath& zip_file,
const DirectoryCreator& directory_creator,
const FilterCallback& filter_cb,
bool log_skipped_files);
#else
#if defined(IN_MEMORY_UPDATES)
// An overload for a zip represented as a string.
bool UnzipWithFilterAndWriters(const std::string& zip_str,
const WriterFactory& writer_factory,
const DirectoryCreator& directory_creator,
const FilterCallback& filter_cb,
bool log_skipped_files);
#endif // defined(IN_MEMORY_UPDATES)
#else // defined(STARBOARD)
bool UnzipWithFilterAndWriters(const base::PlatformFile& zip_file,
const WriterFactory& writer_factory,
const DirectoryCreator& directory_creator,
const FilterCallback& filter_cb,
bool log_skipped_files);
#endif
#endif // defined(STARBOARD)

// Unzip the contents of zip_file into dest_dir.
bool Unzip(const base::FilePath& zip_file, const base::FilePath& dest_dir);
#if defined(IN_MEMORY_UPDATES)
// Unzip the contents of zip_str into dest_dir.
bool Unzip(const std::string& zip_str, const base::FilePath& dest_dir);
#endif

} // namespace zip

Expand Down
Loading