|
|
|
|
@@ -31,6 +31,7 @@
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include "odt.h"
|
|
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
|
|
@@ -50,7 +51,7 @@ extractTemplateDocument(const char* const templateFilename, const char* const te
|
|
|
|
|
pid_t child_pid;
|
|
|
|
|
if ((child_pid = fork()) == 0) {
|
|
|
|
|
/* you are the child */
|
|
|
|
|
char* const args[] = { "unzip", "-d", tempDir, templateFilename, NULL };
|
|
|
|
|
char* const args[] = { "unzip", "-d", (char* const)tempDir, (char* const)templateFilename, NULL };
|
|
|
|
|
freopen("/dev/null", "w", stdout);
|
|
|
|
|
execvp("unzip", args);
|
|
|
|
|
perror("execvp");
|
|
|
|
|
@@ -72,9 +73,40 @@ createOutputDocument(const char* const outputFilename, const char* const tempDir
|
|
|
|
|
pid_t child_pid;
|
|
|
|
|
if ((child_pid = fork()) == 0) {
|
|
|
|
|
/* you are the child */
|
|
|
|
|
|
|
|
|
|
/* In some implementations, realpath will give an error
|
|
|
|
|
* if the file does not exist, so we need to run it on
|
|
|
|
|
* the output directory, not the as-yet nonexistent
|
|
|
|
|
* output filename. That's what all this (below) is for. */
|
|
|
|
|
char outputDir[FILENAME_MAX];
|
|
|
|
|
char outputBase[FILENAME_MAX];
|
|
|
|
|
char outputRealPath[FILENAME_MAX];
|
|
|
|
|
strncpy(outputDir, outputFilename, FILENAME_MAX);
|
|
|
|
|
char *ptr = strrchr(outputDir, '/');
|
|
|
|
|
if (ptr) {
|
|
|
|
|
strncpy(outputBase, ptr + 1, FILENAME_MAX);
|
|
|
|
|
*(ptr + 1) = '\0';
|
|
|
|
|
} else {
|
|
|
|
|
strncpy(outputDir, ".", FILENAME_MAX);
|
|
|
|
|
strncpy(outputBase, outputFilename, FILENAME_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (realpath(outputDir, outputRealPath) == NULL) {
|
|
|
|
|
/* hopefully this doesn't run, but it will give good info
|
|
|
|
|
* if it does */
|
|
|
|
|
perror("realpath");
|
|
|
|
|
fprintf(stderr, "outputFilename was \"%s\"\n", outputFilename);
|
|
|
|
|
char curdir[FILENAME_MAX];
|
|
|
|
|
getcwd(curdir, FILENAME_MAX);
|
|
|
|
|
fprintf(stderr, "curdir was \"%s\"\n", curdir);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Then we append the output filename. */
|
|
|
|
|
strncat(outputRealPath, "/", FILENAME_MAX);
|
|
|
|
|
strncat(outputRealPath, outputBase, FILENAME_MAX);
|
|
|
|
|
|
|
|
|
|
char* const args[] = { "zip", "-r", outputRealPath, "mimetype", ".", NULL };
|
|
|
|
|
realpath(outputFilename, outputRealPath);
|
|
|
|
|
chdir(tempDir);
|
|
|
|
|
freopen("/dev/null", "w", stdout);
|
|
|
|
|
execvp("zip", args);
|
|
|
|
|
@@ -97,7 +129,7 @@ removeDirectory(const char* const tempDir) {
|
|
|
|
|
pid_t child_pid;
|
|
|
|
|
if ((child_pid = fork()) == 0) {
|
|
|
|
|
/* you are the child */
|
|
|
|
|
char* const args[] = { "rm", "-rf", tempDir, NULL };
|
|
|
|
|
char* const args[] = { "rm", "-rf", (char* const)tempDir, NULL };
|
|
|
|
|
freopen("/dev/null", "w", stdout);
|
|
|
|
|
execvp("rm", args);
|
|
|
|
|
perror("execvp");
|
|
|
|
|
|