You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/11/17 12:57:28 UTC
[11/38] celix git commit: CELIX-288: Fix issue inspecting if file is
a dir. Using stats instead of dirent.type
CELIX-288: Fix issue inspecting if file is a dir. Using stats instead of dirent.type
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/bffb8eaa
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/bffb8eaa
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/bffb8eaa
Branch: refs/heads/develop
Commit: bffb8eaaf01bb5536f3855f82b355cab07d5a771
Parents: 0133d04
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Nov 12 09:06:26 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Nov 12 17:40:17 2015 +0100
----------------------------------------------------------------------
framework/private/src/bundle_archive.c | 49 +++++++++++++++++------------
framework/private/src/bundle_cache.c | 43 ++++++++++++++-----------
2 files changed, 54 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/bffb8eaa/framework/private/src/bundle_archive.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c
index b126617..f7add7e 100644
--- a/framework/private/src/bundle_archive.c
+++ b/framework/private/src/bundle_archive.c
@@ -193,14 +193,20 @@ celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bun
struct dirent dent;
struct dirent *result;
+ struct stat st;
int rc;
rc = readdir_r(archive->archiveRootDir, &dent, &result);
-
while (rc == 0 && result != NULL) {
- if (dent.d_type == DT_DIR && (strncmp(dent.d_name, "version", 7) == 0)) {
+ char subdir[512];
+ snprintf(subdir, 512, "%s/%s", archiveRoot, dent.d_name);
+ stat(subdir, &st);
+ if (S_ISDIR(st.st_mode) && (strncmp(dent.d_name, "version", 7) == 0)) {
sscanf(dent.d_name, "version%*d.%ld", &idx);
- }
+ } else {
+ status = CELIX_FILE_IO_EXCEPTION;
+ break;
+ }
rc = readdir_r(archive->archiveRootDir, &dent, &result);
}
@@ -720,23 +726,26 @@ static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, char *
struct dirent *result = NULL;
int rc = 0;
- rc = readdir_r(dir, &dp, &result);
- while (rc == 0 && result != NULL) {
- if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) {
- char subdir[512];
- snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp.d_name);
-
- if (dp.d_type == DT_DIR) {
- status = bundleArchive_deleteTree(archive, subdir);
- } else {
- if (remove(subdir) != 0) {
- status = CELIX_FILE_IO_EXCEPTION;
- break;
- }
- }
- }
- rc = readdir_r(dir, &dp, &result);
- }
+ rc = readdir_r(dir, &dp, &result);
+ while (rc == 0 && result != NULL) {
+ if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) {
+ char subdir[512];
+ snprintf(subdir, 512, "%s/%s", directory, dp.d_name);
+
+ struct stat st;
+ if (stat(subdir, &st) == 0) {
+ if (S_ISDIR (st.st_mode)) {
+ status = bundleArchive_deleteTree(archive, subdir);
+ } else {
+ if (remove(subdir) != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ break;
+ }
+ }
+ }
+ }
+ rc = readdir_r(dir, &dp, &result);
+ }
if (closedir(dir) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
http://git-wip-us.apache.org/repos/asf/celix/blob/bffb8eaa/framework/private/src/bundle_cache.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_cache.c b/framework/private/src/bundle_cache.c
index efe4f01..46a43e4 100644
--- a/framework/private/src/bundle_cache.c
+++ b/framework/private/src/bundle_cache.c
@@ -74,14 +74,15 @@ celix_status_t bundleCache_destroy(bundle_cache_pt *cache) {
}
celix_status_t bundleCache_delete(bundle_cache_pt cache) {
- printf("DELETING CACHE DIR: %s\n", cache->cacheDir);
return bundleCache_deleteTree(cache, cache->cacheDir);
}
celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *archives) {
- celix_status_t status;
+ celix_status_t status = CELIX_SUCCESS;
DIR *dir;
+ struct stat st;
+
dir = opendir(cache->cacheDir);
if (dir == NULL && errno == ENOENT) {
@@ -103,16 +104,18 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc
snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dp.d_name);
- if (dp.d_type == DT_DIR
- && (strcmp((dp.d_name), ".") != 0)
- && (strcmp((dp.d_name), "..") != 0)
- && (strncmp(dp.d_name, "bundle", 6) == 0)
- && (strcmp(dp.d_name, "bundle0") != 0)) {
-
- bundle_archive_pt archive = NULL;
- status = bundleArchive_recreate(strdup(archiveRoot), &archive);
- if (status == CELIX_SUCCESS) {
- arrayList_add(list, archive);
+ if (stat (archiveRoot, &st) == 0) {
+ if (S_ISDIR (st.st_mode)
+ && (strcmp((dp.d_name), ".") != 0)
+ && (strcmp((dp.d_name), "..") != 0)
+ && (strncmp(dp.d_name, "bundle", 6) == 0)
+ && (strcmp(dp.d_name, "bundle0") != 0)) {
+
+ bundle_archive_pt archive = NULL;
+ status = bundleArchive_recreate(strdup(archiveRoot), &archive);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(list, archive);
+ }
}
}
@@ -158,6 +161,8 @@ celix_status_t bundleCache_createArchive(bundle_cache_pt cache, long id, char *
static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory) {
DIR *dir;
celix_status_t status = CELIX_SUCCESS;
+ struct stat st;
+
dir = opendir(directory);
if (dir == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
@@ -171,12 +176,14 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc
char subdir[512];
snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp.d_name);
- if (dp.d_type == DT_DIR) {
- status = bundleCache_deleteTree(cache, subdir);
- } else {
- if (remove(subdir) != 0) {
- status = CELIX_FILE_IO_EXCEPTION;
- break;
+ if (stat(subdir, &st) == 0) {
+ if (S_ISDIR (st.st_mode)) {
+ status = bundleCache_deleteTree(cache, subdir);
+ } else {
+ if (remove(subdir) != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ break;
+ }
}
}
}