@@ -180,17 +180,6 @@ std::optional<ZipCompression> CompressionFromRaw(uint16_t method) {
180180
181181} // namespace
182182
183- struct ReadableZip ::Impl {
184- // This may not actually be writable. The Impl class is shared between
185- // ReadableZip and WritableZip, and only reading methods will be called from
186- // ReadableZip.
187- Impl (ManagedZip raw, WritableZipSource source)
188- : raw_(std::move(raw)), source_(std::move(source)) {}
189-
190- ManagedZip raw_;
191- WritableZipSource source_;
192- };
193-
194183Result<ReadableZipSource> ReadableZipSource::FromCallbacks (
195184 std::unique_ptr<ReadableZipSourceCallback> callbacks) {
196185 CF_EXPECT (callbacks.get ());
@@ -424,17 +413,17 @@ Result<ReadableZip> ReadableZip::FromSource(SeekableZipSource source) {
424413
425414 WritableZipSource fake_writable_source (std::move (source.raw_ ));
426415
427- return ReadableZip (std::make_unique<Impl>(std::move (zip_ret),
428- std::move (fake_writable_source)));
416+ return ReadableZip (std::move (zip_ret), std::move (fake_writable_source));
429417}
430418
419+ // These have to be defined in the `.cc` file to avoid linker errors because of
420+ // bazel weirdness around cmake files.
431421ReadableZip::ReadableZip (ReadableZip&&) = default ;
432422ReadableZip::~ReadableZip () = default ;
433423ReadableZip& ReadableZip::operator =(ReadableZip&&) = default ;
434424
435425Result<uint64_t > ReadableZip::NumEntries () {
436- CF_EXPECT (impl_.get ());
437- zip_t * raw_zip = CF_EXPECT (impl_->raw_ .get ());
426+ zip_t * raw_zip = CF_EXPECT (raw_.get ());
438427
439428 int64_t entries = zip_get_num_entries (raw_zip, 0 );
440429 CF_EXPECT_GE (entries, 0 , ZipErrorString (raw_zip));
@@ -443,8 +432,7 @@ Result<uint64_t> ReadableZip::NumEntries() {
443432}
444433
445434Result<std::string> ReadableZip::EntryName (uint64_t index) {
446- CF_EXPECT (impl_.get ());
447- zip_t * raw_zip = CF_EXPECT (impl_->raw_ .get ());
435+ zip_t * raw_zip = CF_EXPECT (raw_.get ());
448436
449437 const char * name_cstr = zip_get_name (raw_zip, index, 0 );
450438 CF_EXPECT_NE (name_cstr, nullptr , ZipErrorString (raw_zip));
@@ -453,8 +441,7 @@ Result<std::string> ReadableZip::EntryName(uint64_t index) {
453441}
454442
455443Result<uint32_t > ReadableZip::EntryUnixAttributes (uint64_t index) {
456- CF_EXPECT (impl_.get ());
457- zip_t * raw_zip = CF_EXPECT (impl_->raw_ .get ());
444+ zip_t * raw_zip = CF_EXPECT (raw_.get ());
458445
459446 uint8_t opsys;
460447 uint32_t attributes;
@@ -467,8 +454,7 @@ Result<uint32_t> ReadableZip::EntryUnixAttributes(uint64_t index) {
467454}
468455
469456Result<SeekableZipSource> ReadableZip::GetFile (const std::string& name) {
470- CF_EXPECT (impl_.get ());
471- zip_t * raw_zip = CF_EXPECT (impl_->raw_ .get ());
457+ zip_t * raw_zip = CF_EXPECT (raw_.get ());
472458
473459 int64_t index = zip_name_locate (raw_zip, name.c_str (), 0 );
474460 CF_EXPECT_GE (index, 0 , ZipErrorString (raw_zip));
@@ -477,8 +463,7 @@ Result<SeekableZipSource> ReadableZip::GetFile(const std::string& name) {
477463}
478464
479465Result<SeekableZipSource> ReadableZip::GetFile (uint64_t index) {
480- CF_EXPECT (impl_.get ());
481- zip_t * raw_zip = CF_EXPECT (impl_->raw_ .get ());
466+ zip_t * raw_zip = CF_EXPECT (raw_.get ());
482467
483468 ManagedZipError error = NewZipError ();
484469 ManagedZipSource raw_source (zip_source_zip_file_create (
@@ -489,7 +474,8 @@ Result<SeekableZipSource> ReadableZip::GetFile(uint64_t index) {
489474 return SeekableZipSource (std::move (raw_source));
490475}
491476
492- ReadableZip::ReadableZip (std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {}
477+ ReadableZip::ReadableZip (ManagedZip raw, WritableZipSource source)
478+ : raw_(std::move(raw)), source_(std::move(source)) {}
493479
494480Result<WritableZip> WritableZip::FromSource (
495481 WritableZipSource source, WritableZip::OpenBehavior open_behavior) {
@@ -519,18 +505,12 @@ Result<WritableZip> WritableZip::FromSource(WritableZipSource source,
519505 return CF_ERR (ZipErrorString (error.get ()));
520506 }
521507
522- return WritableZip (
523- std::make_unique<Impl>(std::move (zip_ret), std::move (source)));
508+ return WritableZip (std::move (zip_ret), std::move (source));
524509}
525510
526- WritableZip::WritableZip (WritableZip&&) = default ;
527- WritableZip::~WritableZip () = default ;
528- WritableZip& WritableZip::operator =(WritableZip&&) = default ;
529-
530511Result<void > WritableZip::AddFile (const std::string& name,
531512 ReadableZipSource source) {
532- CF_EXPECT (impl_.get ());
533- zip_t * raw_zip = CF_EXPECT (impl_->raw_ .get ());
513+ zip_t * raw_zip = CF_EXPECT (raw_.get ());
534514
535515 zip_source_t * raw_source = CF_EXPECT (source.raw_ .get ());
536516
@@ -543,27 +523,24 @@ Result<void> WritableZip::AddFile(const std::string& name,
543523}
544524
545525Result<void > WritableZip::Finalize (WritableZip zip_cc) {
546- CF_EXPECT (zip_cc.impl_ .get ());
547- zip_t * raw_zip = CF_EXPECT (zip_cc.impl_ ->raw_ .get ());
526+ zip_t * raw_zip = CF_EXPECT (zip_cc.raw_ .get ());
548527
549528 CF_EXPECT_EQ (zip_close (raw_zip), 0 , ZipErrorString (raw_zip));
550529
551- zip_cc.impl_ -> raw_ .release (); // Deleted by zip_close
530+ zip_cc.raw_ .release (); // Deleted by zip_close
552531
553532 return {};
554533}
555534
556535Result<WritableZipSource> WritableZipSource::FromZip (WritableZip zip_cc) {
557- CF_EXPECT (zip_cc.impl_ .get ());
558-
559- WritableZipSource source = std::move (zip_cc.impl_ ->source_ );
536+ WritableZipSource source = std::move (zip_cc.source_ );
560537
561538 CF_EXPECT (WritableZip::Finalize (std::move (zip_cc)));
562539
563540 return source;
564541}
565542
566- WritableZip::WritableZip (std::unique_ptr<Impl> impl )
567- : ReadableZip(std::move(impl )) {}
543+ WritableZip::WritableZip (ManagedZip raw, WritableZipSource source )
544+ : ReadableZip(std::move(raw), std::move(source )) {}
568545
569546} // namespace cuttlefish
0 commit comments