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

Updated minzip library #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Empty file modified libs/minzip/Bits.h
100644 → 100755
Empty file.
78 changes: 17 additions & 61 deletions libs/minzip/DirUtil.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ getPathDirStatus(const char *path)

int
dirCreateHierarchy(const char *path, int mode,
const struct utimbuf *timestamp, bool stripFileName)
const struct utimbuf *timestamp, bool stripFileName,
struct selabel_handle *sehnd)
{
DirStatus ds;

Expand Down Expand Up @@ -84,7 +85,7 @@ dirCreateHierarchy(const char *path, int mode,
c--;
}
if (c == cpath) {
//xxx test this path
//xxx test this path
/* No directory component. Act like the path was empty.
*/
errno = ENOENT;
Expand Down Expand Up @@ -144,7 +145,20 @@ dirCreateHierarchy(const char *path, int mode,
} else if (ds == DMISSING) {
int err;

char *secontext = NULL;

if (sehnd) {
selabel_lookup(sehnd, &secontext, cpath, mode);
setfscreatecon(secontext);
}

err = mkdir(cpath, mode);

if (secontext) {
freecon(secontext);
setfscreatecon(NULL);
}

if (err != 0) {
free(cpath);
return -1;
Expand Down Expand Up @@ -192,7 +206,7 @@ dirUnlinkHierarchy(const char *path)
/* recurse over components */
errno = 0;
while ((de = readdir(dir)) != NULL) {
//TODO: don't blow the stack
//TODO: don't blow the stack
char dn[PATH_MAX];
if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) {
continue;
Expand Down Expand Up @@ -220,61 +234,3 @@ dirUnlinkHierarchy(const char *path)
/* delete target directory */
return rmdir(path);
}

int
dirSetHierarchyPermissions(const char *path,
int uid, int gid, int dirMode, int fileMode)
{
struct stat st;
if (lstat(path, &st)) {
return -1;
}

/* ignore symlinks */
if (S_ISLNK(st.st_mode)) {
return 0;
}

/* directories and files get different permissions */
if (chown(path, uid, gid) ||
chmod(path, S_ISDIR(st.st_mode) ? dirMode : fileMode)) {
return -1;
}

/* recurse over directory components */
if (S_ISDIR(st.st_mode)) {
DIR *dir = opendir(path);
if (dir == NULL) {
return -1;
}

errno = 0;
const struct dirent *de;
while (errno == 0 && (de = readdir(dir)) != NULL) {
if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) {
continue;
}

char dn[PATH_MAX];
snprintf(dn, sizeof(dn), "%s/%s", path, de->d_name);
if (!dirSetHierarchyPermissions(dn, uid, gid, dirMode, fileMode)) {
errno = 0;
} else if (errno == 0) {
errno = -1;
}
}

if (errno != 0) {
int save = errno;
closedir(dir);
errno = save;
return -1;
}

if (closedir(dir)) {
return -1;
}
}

return 0;
}
20 changes: 12 additions & 8 deletions libs/minzip/DirUtil.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#include <stdbool.h>
#include <utime.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <selinux/selinux.h>
#include <selinux/label.h>

/* Like "mkdir -p", try to guarantee that all directories
* specified in path are present, creating as many directories
* as necessary. The specified mode is passed to all mkdir
Expand All @@ -34,18 +41,15 @@
* (usually if some element of path is not a directory).
*/
int dirCreateHierarchy(const char *path, int mode,
const struct utimbuf *timestamp, bool stripFileName);
const struct utimbuf *timestamp, bool stripFileName,
struct selabel_handle* sehnd);

/* rm -rf <path>
*/
int dirUnlinkHierarchy(const char *path);

/* chown -R <uid>:<gid> <path>
* chmod -R <mode> <path>
*
* Sets directories to <dirMode> and files to <fileMode>. Skips symlinks.
*/
int dirSetHierarchyPermissions(const char *path,
int uid, int gid, int dirMode, int fileMode);
#ifdef __cplusplus
}
#endif

#endif // MINZIP_DIRUTIL_H_
15 changes: 2 additions & 13 deletions libs/minzip/Hash.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ static bool resizeHash(HashTable* pHashTable, int newSize)
int i;

assert(countTombStones(pHashTable) == pHashTable->numDeadEntries);
//LOGI("before: dead=%d\n", pHashTable->numDeadEntries);

pNewEntries = (HashEntry*) calloc(newSize, sizeof(HashTable));
if (pNewEntries == NULL)
Expand Down Expand Up @@ -196,7 +195,6 @@ void* mzHashTableLookup(HashTable* pHashTable, unsigned int itemHash, void* item
(*cmpFunc)(pEntry->data, item) == 0)
{
/* match */
//LOGD("+++ match on entry %d\n", pEntry - pHashTable->pEntries);
break;
}

Expand All @@ -206,8 +204,6 @@ void* mzHashTableLookup(HashTable* pHashTable, unsigned int itemHash, void* item
break; /* edge case - single-entry table */
pEntry = pHashTable->pEntries;
}

//LOGI("+++ look probing %d...\n", pEntry - pHashTable->pEntries);
}

if (pEntry->data == NULL) {
Expand All @@ -228,10 +224,6 @@ void* mzHashTableLookup(HashTable* pHashTable, unsigned int itemHash, void* item
abort();
}
/* note "pEntry" is now invalid */
} else {
//LOGW("okay %d/%d/%d\n",
// pHashTable->numEntries, pHashTable->tableSize,
// (pHashTable->tableSize * LOAD_NUMER) / LOAD_DENOM);
}

/* full table is bad -- search for nonexistent never halts */
Expand Down Expand Up @@ -264,7 +256,6 @@ bool mzHashTableRemove(HashTable* pHashTable, unsigned int itemHash, void* item)
pEnd = &pHashTable->pEntries[pHashTable->tableSize];
while (pEntry->data != NULL) {
if (pEntry->data == item) {
//LOGI("+++ stepping on entry %d\n", pEntry - pHashTable->pEntries);
pEntry->data = HASH_TOMBSTONE;
pHashTable->numEntries--;
pHashTable->numDeadEntries++;
Expand All @@ -277,8 +268,6 @@ bool mzHashTableRemove(HashTable* pHashTable, unsigned int itemHash, void* item)
break; /* edge case - single-entry table */
pEntry = pHashTable->pEntries;
}

//LOGI("+++ del probing %d...\n", pEntry - pHashTable->pEntries);
}

return false;
Expand Down Expand Up @@ -372,7 +361,7 @@ void mzHashTableProbeCount(HashTable* pHashTable, HashCalcFunc calcFunc,
{
const void* data = (const void*)mzHashIterData(&iter);
int count;

count = countProbes(pHashTable, (*calcFunc)(data), data, cmpFunc);

numEntries++;
Expand All @@ -384,7 +373,7 @@ void mzHashTableProbeCount(HashTable* pHashTable, HashCalcFunc calcFunc,
totalProbe += count;
}

LOGI("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f\n",
LOGV("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f\n",
minProbe, maxProbe, totalProbe, numEntries, pHashTable->tableSize,
(float) totalProbe / (float) numEntries);
}
8 changes: 8 additions & 0 deletions libs/minzip/Hash.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <stdbool.h>
#include <assert.h>

#ifdef __cplusplus
extern "C" {
#endif

/* compute the hash of an item with a specific type */
typedef unsigned int (*HashCompute)(const void* item);

Expand Down Expand Up @@ -183,4 +187,8 @@ typedef unsigned int (*HashCalcFunc)(const void* item);
void mzHashTableProbeCount(HashTable* pHashTable, HashCalcFunc calcFunc,
HashCompareFunc cmpFunc);

#ifdef __cplusplus
}
#endif

#endif /*_MINZIP_HASH*/
Empty file modified libs/minzip/Inlines.c
100644 → 100755
Empty file.
3 changes: 0 additions & 3 deletions libs/minzip/Log.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

// ---------------------------------------------------------------------

#define NDEBUG
#define LOG_NDEBUG 1

/*
* Normally we strip LOGV (VERBOSE messages) from release builds.
* You can modify this (for example with "#define LOG_NDEBUG 0"
Expand Down
Loading