You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2016/07/22 12:28:48 UTC

[4/9] lucy-clownfish git commit: Make CFCUtil_write_file create target directory

Make CFCUtil_write_file create target directory


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/73832f18
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/73832f18
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/73832f18

Branch: refs/heads/master
Commit: 73832f18a6d4d562d7700299e7bcca6a128608ea
Parents: 978b013
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Jul 15 14:08:42 2016 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Jul 15 22:09:57 2016 +0200

----------------------------------------------------------------------
 compiler/src/CFCBindFile.c      | 15 ---------------
 compiler/src/CFCC.c             |  6 ------
 compiler/src/CFCCHtml.c         | 21 ---------------------
 compiler/src/CFCHierarchy.c     | 15 ---------------
 compiler/src/CFCPerl.c          | 10 ----------
 compiler/src/CFCTestHierarchy.c |  4 +---
 compiler/src/CFCUtil.c          |  9 +++++++++
 7 files changed, 10 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCBindFile.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindFile.c b/compiler/src/CFCBindFile.c
index 26c215c..f7d9e51 100644
--- a/compiler/src/CFCBindFile.c
+++ b/compiler/src/CFCBindFile.c
@@ -35,22 +35,7 @@ CFCBindFile_write_h(CFCFile *file, const char *dest, const char *header,
     CFCUTIL_NULL_CHECK(header);
     CFCUTIL_NULL_CHECK(footer);
 
-    // Make directories.
     char *h_path = CFCFile_h_path(file, dest);
-    char *h_dir  = CFCUtil_strdup(h_path);
-    for (size_t len = strlen(h_dir); len--;) {
-        if (h_dir[len] == CHY_DIR_SEP_CHAR) {
-            h_dir[len] = 0;
-            break;
-        }
-    }
-    if (!CFCUtil_is_dir(h_dir)) {
-        CFCUtil_make_path(h_dir);
-        if (!CFCUtil_is_dir(h_dir)) {
-            CFCUtil_die("Can't make path %s", h_dir);
-        }
-    }
-    FREEMEM(h_dir);
 
     // Create the include-guard strings.
     const char *include_guard_start = CFCFile_guard_start(file);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCC.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCC.c b/compiler/src/CFCC.c
index 698de51..6197e2e 100644
--- a/compiler/src/CFCC.c
+++ b/compiler/src/CFCC.c
@@ -110,12 +110,6 @@ CFCC_write_man_pages(CFCC *self) {
     const char *dest = CFCHierarchy_get_dest(hierarchy);
     char *man3_path
         = CFCUtil_sprintf("%s" CHY_DIR_SEP "man" CHY_DIR_SEP "man3", dest);
-    if (!CFCUtil_is_dir(man3_path)) {
-        CFCUtil_make_path(man3_path);
-        if (!CFCUtil_is_dir(man3_path)) {
-            CFCUtil_die("Can't make path %s", man3_path);
-        }
-    }
 
     // Write out any man pages that have changed.
     for (size_t i = 0, j = 0; ordered[i] != NULL; i++) {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCCHtml.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCCHtml.c b/compiler/src/CFCCHtml.c
index 72e4748..a70f626 100644
--- a/compiler/src/CFCCHtml.c
+++ b/compiler/src/CFCCHtml.c
@@ -295,30 +295,9 @@ CFCCHtml_write_html_docs(CFCCHtml *self) {
         char *filename = filenames[i];
         char *path     = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s", doc_path,
                                          filename);
-
-        // Make path.
-
-        char *dir  = CFCUtil_strdup(path);
-        for (size_t j = strlen(dir); j--;) {
-            if (dir[j] == CHY_DIR_SEP_CHAR) {
-                do {
-                    dir[j] = '\0';
-                } while (j-- && dir[j] == CHY_DIR_SEP_CHAR);
-                break;
-            }
-        }
-
-        if (dir[0] != '\0' && !CFCUtil_is_dir(dir)) {
-            CFCUtil_make_path(dir);
-            if (!CFCUtil_is_dir(dir)) {
-                CFCUtil_die("Can't make path %s", dir);
-            }
-        }
-
         char *html_doc = html_docs[i];
         CFCUtil_write_if_changed(path, html_doc, strlen(html_doc));
         FREEMEM(html_doc);
-        FREEMEM(dir);
         FREEMEM(path);
         FREEMEM(filename);
     }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index fa09c5e..68a5d88 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -67,9 +67,6 @@ typedef struct CFCFindFilesContext {
 } CFCFindFilesContext;
 
 static void
-S_do_make_path(const char *path);
-
-static void
 S_parse_parcel_files(const char *source_dir, int is_included);
 
 static void
@@ -139,8 +136,6 @@ CFCHierarchy_init(CFCHierarchy *self, const char *dest) {
 
     self->inc_dest = CFCUtil_sprintf("%s" CHY_DIR_SEP "include", self->dest);
     self->src_dest = CFCUtil_sprintf("%s" CHY_DIR_SEP "source", self->dest);
-    S_do_make_path(self->inc_dest);
-    S_do_make_path(self->src_dest);
 
     return self;
 }
@@ -169,16 +164,6 @@ CFCHierarchy_destroy(CFCHierarchy *self) {
     CFCBase_destroy((CFCBase*)self);
 }
 
-static void
-S_do_make_path(const char *path) {
-    if (!CFCUtil_is_dir(path)) {
-        CFCUtil_make_path(path);
-        if (!CFCUtil_is_dir(path)) {
-            CFCUtil_die("Can't make path %s", path);
-        }
-    }
-}
-
 void
 CFCHierarchy_add_source_dir(CFCHierarchy *self, const char *source_dir) {
     // Don't add directory twice.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index f038a8c..62a7f48 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -150,15 +150,6 @@ CFCPerl_write_pod(CFCPerl *self) {
         for (size_t i = 0; pod_files[i].contents; i++) {
             char *pod      = pod_files[i].contents;
             char *pod_path = pod_files[i].path;
-            char *pod_dir  = CFCUtil_strdup(pod_path);
-
-            char *last_dir_sep = strrchr(pod_dir, CHY_DIR_SEP_CHAR);
-            if (last_dir_sep) {
-                *last_dir_sep = '\0';
-                if (!CFCUtil_make_path(pod_dir)) {
-                    CFCUtil_die("Can't make path %s", pod_dir);
-                }
-            }
 
             if (CFCUtil_write_if_changed(pod_path, pod, strlen(pod))) {
                 pod_paths[num_written] = pod_path;
@@ -169,7 +160,6 @@ CFCPerl_write_pod(CFCPerl *self) {
             }
 
             FREEMEM(pod);
-            FREEMEM(pod_dir);
         }
 
         FREEMEM(pod_files);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCTestHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestHierarchy.c b/compiler/src/CFCTestHierarchy.c
index 83f9081..4df8c5f 100644
--- a/compiler/src/CFCTestHierarchy.c
+++ b/compiler/src/CFCTestHierarchy.c
@@ -55,7 +55,7 @@ S_run_clash_tests(CFCTest *test);
 
 const CFCTestBatch CFCTEST_BATCH_HIERARCHY = {
     "Clownfish::CFC::Model::Hierarchy",
-    48,
+    47,
     S_run_tests
 };
 
@@ -132,8 +132,6 @@ S_run_basic_tests(CFCTest *test) {
         AUTOGEN_INCLUDE CHY_DIR_SEP "Animal" CHY_DIR_SEP "Dog.h",
         AUTOGEN_INCLUDE CHY_DIR_SEP "Animal" CHY_DIR_SEP "Util.h"
     };
-    OK(test, CFCUtil_make_path(AUTOGEN_INCLUDE CHY_DIR_SEP "Animal"),
-       "make_path");
     for (int i = 0; i < 3; ++i) {
         const char *h_path  = h_paths[i];
         const char *content = "#include <stdio.h>\n";

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/73832f18/compiler/src/CFCUtil.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.c b/compiler/src/CFCUtil.c
index f153904..edc9c17 100644
--- a/compiler/src/CFCUtil.c
+++ b/compiler/src/CFCUtil.c
@@ -380,6 +380,15 @@ CFCUtil_current(const char *orig, const char *dest) {
 
 void
 CFCUtil_write_file(const char *filename, const char *content, size_t len) {
+    const char *last_sep = strrchr(filename, CHY_DIR_SEP_CHAR);
+    if (last_sep != NULL && last_sep != filename) {
+        char *dir = CFCUtil_strndup(filename, last_sep - filename);
+        if (!CFCUtil_is_dir(dir) && !CFCUtil_make_path(dir)) {
+            CFCUtil_die("Couldn't create directory '%s'", dir);
+        }
+        FREEMEM(dir);
+    }
+
     FILE *fh = fopen(filename, "w+");
     if (fh == NULL) {
         CFCUtil_die("Couldn't open '%s': %s", filename, strerror(errno));