MCPcopy Create free account
hub / github.com/CyanogenMod/android_frameworks_base / open

Method open

tools/aapt/ZipFile.cpp:59–130  ·  view source on GitHub ↗

* Open a file and parse its guts. */

Source from the content-addressed store, hash-verified

57 * Open a file and parse its guts.
58 */
59status_t ZipFile::open(const char* zipFileName, int flags)
60{
61 bool newArchive = false;
62
63 assert(mZipFp == NULL); // no reopen
64
65 if ((flags & kOpenTruncate))
66 flags |= kOpenCreate; // trunc implies create
67
68 if ((flags & kOpenReadOnly) && (flags & kOpenReadWrite))
69 return INVALID_OPERATION; // not both
70 if (!((flags & kOpenReadOnly) || (flags & kOpenReadWrite)))
71 return INVALID_OPERATION; // not neither
72 if ((flags & kOpenCreate) && !(flags & kOpenReadWrite))
73 return INVALID_OPERATION; // create requires write
74
75 if (flags & kOpenTruncate) {
76 newArchive = true;
77 } else {
78 newArchive = (access(zipFileName, F_OK) != 0);
79 if (!(flags & kOpenCreate) && newArchive) {
80 /* not creating, must already exist */
81 ALOGD("File %s does not exist", zipFileName);
82 return NAME_NOT_FOUND;
83 }
84 }
85
86 /* open the file */
87 const char* openflags;
88 if (flags & kOpenReadWrite) {
89 if (newArchive)
90 openflags = FILE_OPEN_RW_CREATE;
91 else
92 openflags = FILE_OPEN_RW;
93 } else {
94 openflags = FILE_OPEN_RO;
95 }
96 mZipFp = fopen(zipFileName, openflags);
97 if (mZipFp == NULL) {
98 int err = errno;
99 ALOGD("fopen failed: %d\n", err);
100 return errnoToStatus(err);
101 }
102
103 status_t result;
104 if (!newArchive) {
105 /*
106 * Load the central directory. If that fails, then this probably
107 * isn't a Zip archive.
108 */
109 result = readCentralDir();
110 } else {
111 /*
112 * Newly-created. The EndOfCentralDir constructor actually
113 * sets everything to be the way we want it (all zeroes). We
114 * set mNeedCDRewrite so that we create *something* if the
115 * caller doesn't add any files. (We could also just unlink
116 * the file if it's brand new and nothing was added, but that's

Callers 15

openReadOnlyFunction · 0.45
openReadWriteFunction · 0.45
slurpResourceZipMethod · 0.45
writeAPKFunction · 0.45
processJarFilesFunction · 0.45
DrmManagerClientMethod · 0.45
get_deviceFunction · 0.45
InitFunction · 0.45
halOpenFunction · 0.45
cleanUpMethod · 0.45
runMethod · 0.45

Calls 1

errnoToStatusFunction · 0.85

Tested by 11

cleanUpMethod · 0.36
runMethod · 0.36
testFaceSquareFilterMethod · 0.36
testBrightnessFilterMethod · 0.36
testContrastFilterMethod · 0.36
testExposureFilterMethod · 0.36
testIfElseFilterTrueMethod · 0.36
testIfElseFilterFalseMethod · 0.36
doInBackgroundMethod · 0.36
loadBitmapMethod · 0.36