corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [12/38] incubator-corinthia git commit: Get rid of DFCreateTempDir
Date Fri, 13 Feb 2015 08:52:24 GMT
Get rid of DFCreateTempDir

For a number of operations, like running tests and converting documents,
we used to require the existence of a temporary directory into which we
could extract the contents of a .docx or other zip-based package.
However, since the implementation of the DFStorage interface, with both
an in-memory implementation, and a zip-based implementation, it's no
longer necessary to write the XML files from a zip package out to the
filesystem.

DFCreateTempDir used to rely on mkdtemp, which generates temporary
directories in a secure manner (that is, avoiding a race condition
between the directory's creation time and the application getting
exclusive access to it). However, this function is not available on
windows, leaving us with the choice of having an #ifdef WIN32 to use a
fixed directory name on windows, or doing the same thing on all
platforms. Compiling on Linux would give a warning about the mktemp
function being unsafe.

Given that we don't actually need temporary directories any more for
testing or conversion though, we can just remove this function
altogethter, avoiding this dilemma.

The one place where temporary files are still used is when dftest is run
with the -diff option, which prints out the differences between the
expected and actual results of a test case if there is a failure. This
has been changed to use the fixed filenames 'dftest-diff-from.tmp' and
'dftest-diff-to.tmp' so it can run the diff command as a sub-process.

Another nice advantage of this is when dftest or dfutil crashes, you
don't get a dfutil.XXXXXX directory lying around.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/5204f74e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/5204f74e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/5204f74e

Branch: refs/heads/experimentZip
Commit: 5204f74e892e98e5b877a79946b208a2279eed5c
Parents: 22947ef
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Sun Jan 11 01:58:29 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Sun Jan 11 02:08:12 2015 +0700

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFFilesystem.c | 16 ----------------
 DocFormats/core/src/lib/DFFilesystem.h |  1 -
 consumers/dftest/src/main.c            | 24 ++++++------------------
 consumers/dfutil/src/Commands.c        | 23 ++---------------------
 4 files changed, 8 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5204f74e/DocFormats/core/src/lib/DFFilesystem.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFFilesystem.c b/DocFormats/core/src/lib/DFFilesystem.c
index 972941b..66c8a79 100644
--- a/DocFormats/core/src/lib/DFFilesystem.c
+++ b/DocFormats/core/src/lib/DFFilesystem.c
@@ -392,19 +392,3 @@ char *DFRemovePercentEncoding(const char *encoded)
     output[outpos] = 0;
     return output;
 }
-
-
-char *DFCreateTempDir(DFError **error)
-{
-    char *ctemplate = strdup("dfutil.XXXXXX");
-    char *name      = mktemp(ctemplate);
-    if (!name) {
-        free(ctemplate);
-        return NULL;
-    }
-    if (!DFCreateDirectory(name, 1, error)) {
-        free(ctemplate);
-        return NULL;
-    }
-    return name;
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5204f74e/DocFormats/core/src/lib/DFFilesystem.h
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFFilesystem.h b/DocFormats/core/src/lib/DFFilesystem.h
index b1536e1..e3e2869 100644
--- a/DocFormats/core/src/lib/DFFilesystem.h
+++ b/DocFormats/core/src/lib/DFFilesystem.h
@@ -34,5 +34,4 @@ char *DFPathWithoutExtension(const char *path);
 char *DFPathResolveAbsolute(const char *base, const char *relative);
 char *DFPathNormalize(const char *path);
 char *DFRemovePercentEncoding(const char *encoded);
-char *DFCreateTempDir(DFError **error);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5204f74e/consumers/dftest/src/main.c
----------------------------------------------------------------------
diff --git a/consumers/dftest/src/main.c b/consumers/dftest/src/main.c
index 1cc1f69..b3fd6b0 100644
--- a/consumers/dftest/src/main.c
+++ b/consumers/dftest/src/main.c
@@ -60,10 +60,10 @@ typedef struct {
     int failed;
 } TestHarness;
 
-static int diffResults2(const char *from, const char *to, const char *tempDir, DFError **error)
+static int diffResults(const char *from, const char *to, DFError **error)
 {
-    char *fromFilename = DFAppendPathComponent(tempDir,"from");
-    char *toFilename = DFAppendPathComponent(tempDir,"to");
+    const char *fromFilename = "dftest-diff-from.tmp";
+    const char *toFilename = "dftest-diff-to.tmp";
     int result = 0;
     if (!DFStringWriteToFile(from,fromFilename,error)) {
         DFErrorFormat(error,"%s: %s",fromFilename,DFErrorMessage(error));
@@ -72,25 +72,13 @@ static int diffResults2(const char *from, const char *to, const char *tempDir,
D
         DFErrorFormat(error,"%s: %s",toFilename,DFErrorMessage(error));
     }
     else {
-        char *cmd = DFFormatString("diff -u %s/from %s/to",tempDir,tempDir);
+        char *cmd = DFFormatString("diff -u %s %s",fromFilename,toFilename);
         system(cmd);
         free(cmd);
         result = 1;
     }
-    free(fromFilename);
-    free(toFilename);
-    return result;
-}
-
-static int diffResults(const char *from, const char *to, DFError **error)
-{
-    char *tempDir = DFCreateTempDir(error);
-    if (tempDir == NULL)
-        return 0;
-
-    int result = diffResults2(from,to,tempDir,error);
-    DFDeleteFile(tempDir,NULL);
-    free(tempDir);
+    DFDeleteFile(fromFilename,NULL);
+    DFDeleteFile(toFilename,NULL);
     return result;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5204f74e/consumers/dfutil/src/Commands.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.c b/consumers/dfutil/src/Commands.c
index f1054d9..530acd2 100644
--- a/consumers/dfutil/src/Commands.c
+++ b/consumers/dfutil/src/Commands.c
@@ -102,17 +102,10 @@ static int prettyPrintXMLFile(const char *filename, int html, DFError
**error)
 
 static int prettyPrintWordFile(const char *filename, DFError **error)
 {
-    char *tempPath = DFCreateTempDir(error);
-    if (tempPath == NULL)
-        return 0;;
     int ok = 0;
-    char *wordTempPath = DFAppendPathComponent(tempPath,"word");
     char *plain = NULL;
     DFStorage *storage = NULL;
 
-    if (!DFEmptyDirectory(wordTempPath,error))
-        goto end;
-
     storage = DFStorageOpenZip(filename,error);
     if (storage == NULL) {
         DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
@@ -125,11 +118,8 @@ static int prettyPrintWordFile(const char *filename, DFError **error)
     ok = 1;
 
 end:
-    free(tempPath);
-    free(wordTempPath);
     free(plain);
     DFStorageRelease(storage);
-    DFDeleteFile(tempPath,NULL);
     return ok;
 }
 
@@ -151,8 +141,7 @@ int prettyPrintFile(const char *filename, DFError **error)
     return ok;
 }
 
-static int fromPlain2(const char *tempPath, const char *inStr, const char *inPath,
-                      const char *outFilename, DFError **error)
+static int fromPlain2(const char *inStr, const char *inPath, const char *outFilename, DFError
**error)
 {
     char *outExtension = DFPathExtension(outFilename);
     int isDocx = DFStringEqualsCI(outExtension,"docx");
@@ -185,17 +174,9 @@ int fromPlain(const char *inFilename, const char *outFilename, DFError
**error)
     if (inStr == NULL)
         return 0;
 
-    char *tempPath = DFCreateTempDir(error);
-    if (tempPath == NULL) {
-        free(inStr);
-        return 0;
-    }
-
     char *inPath = fromStdin ? strdup(".") : DFPathDirName(inFilename);
-    int ok = fromPlain2(tempPath,inStr,inPath,outFilename,error);
-    DFDeleteFile(tempPath,NULL);
+    int ok = fromPlain2(inStr,inPath,outFilename,error);
     free(inPath);
-    free(tempPath);
     free(inStr);
     return ok;
 }


Mime
View raw message