AAPT2: Fix up file IO
This also enables an AAPT behavior that CTS tests have
come to depend on.
Small files that compress negatively (get larger) are stored
uncompressed. Some CTS tests assume this and try to open these
files by mmapping them, which is only possible if they are
uncompressed.
Bug: 35461578
Test: make aapt2_tests
Change-Id: Id622a6150fe72477ad65d67d1bad897a8ee2ffb9
diff --git a/tools/aapt2/io/File.h b/tools/aapt2/io/File.h
index 1ef9743..7ef6d88 100644
--- a/tools/aapt2/io/File.h
+++ b/tools/aapt2/io/File.h
@@ -30,40 +30,27 @@
namespace aapt {
namespace io {
-/**
- * Interface for a file, which could be a real file on the file system, or a
- * file inside
- * a ZIP archive.
- */
+// Interface for a file, which could be a real file on the file system, or a
+// file inside a ZIP archive.
class IFile {
public:
virtual ~IFile() = default;
- /**
- * Open the file and return it as a block of contiguous memory. How this
- * occurs is
- * implementation dependent. For example, if this is a file on the file
- * system, it may
- * simply mmap the contents. If this file represents a compressed file in a
- * ZIP archive,
- * it may need to inflate it to memory, incurring a copy.
- *
- * Returns nullptr on failure.
- */
+ // Open the file and return it as a block of contiguous memory. How this
+ // occurs is implementation dependent. For example, if this is a file on the file
+ // system, it may simply mmap the contents. If this file represents a compressed file in a
+ // ZIP archive, it may need to inflate it to memory, incurring a copy.
+ // Returns nullptr on failure.
virtual std::unique_ptr<IData> OpenAsData() = 0;
- /**
- * Returns the source of this file. This is for presentation to the user and
- * may not be a
- * valid file system path (for example, it may contain a '@' sign to separate
- * the files within
- * a ZIP archive from the path to the containing ZIP archive.
- */
+ // Returns the source of this file. This is for presentation to the user and
+ // may not be a valid file system path (for example, it may contain a '@' sign to separate
+ // the files within a ZIP archive from the path to the containing ZIP archive.
virtual const Source& GetSource() const = 0;
IFile* CreateFileSegment(size_t offset, size_t len);
- /** Returns whether the file was compressed before it was stored in memory. */
+ // Returns whether the file was compressed before it was stored in memory.
virtual bool WasCompressed() {
return false;
}
@@ -77,10 +64,7 @@
std::list<std::unique_ptr<IFile>> segments_;
};
-/**
- * An IFile that wraps an underlying IFile but limits it to a subsection of that
- * file.
- */
+// An IFile that wraps an underlying IFile but limits it to a subsection of that file.
class FileSegment : public IFile {
public:
explicit FileSegment(IFile* file, size_t offset, size_t len)
@@ -106,11 +90,8 @@
virtual IFile* Next() = 0;
};
-/**
- * Interface for a collection of files, all of which share a common source. That
- * source may
- * simply be the filesystem, or a ZIP archive.
- */
+// Interface for a collection of files, all of which share a common source. That source may
+// simply be the filesystem, or a ZIP archive.
class IFileCollection {
public:
virtual ~IFileCollection() = default;