From e4c14462569cfb21c0d5b6425d8c256c063b7511 Mon Sep 17 00:00:00 2001 From: Matt Mascarenhas Date: Sun, 24 Dec 2017 01:57:11 +0000 Subject: [PATCH] cinera.c: Call MakeDir() in GenerateTopicColours() --- cinera/cinera.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/cinera/cinera.c b/cinera/cinera.c index a8966b6..d8d156f 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -14,9 +14,10 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 5, - .Patch = 13 + .Patch = 14 }; +// TODO(matt): Copy in the DB 3 stuff from cinera_working.c #define CINERA_DB_VERSION 2 #define DEBUG 0 @@ -1600,6 +1601,25 @@ GenerateTopicColours(char *Topic) CopyString(Topics.Path, "%s/cinera_topics.css", Config.RootDir); } + char *Ptr = Topics.Path + StringLength(Topics.Path) - 1; + while(*Ptr != '/') + { + --Ptr; + } + *Ptr = '\0'; + DIR *CSSDirHandle; // TODO(matt): open() + if(!(CSSDirHandle = opendir(Topics.Path))) + { + if(MakeDir(Topics.Path) == RC_ERROR_DIRECTORY) + { + LogError(LOG_ERROR, "Unable to create directory %s: %s", Topics.Path, strerror(errno)); + fprintf(stderr, "Unable to create directory %s: %s\n", Topics.Path, strerror(errno)); + return RC_ERROR_DIRECTORY; + }; + } + closedir(CSSDirHandle); + *Ptr = '/'; + if((Topics.Handle = fopen(Topics.Path, "a+"))) { fseek(Topics.Handle, 0, SEEK_END); @@ -1649,6 +1669,8 @@ GenerateTopicColours(char *Topic) } else { + // NOTE(matt): Maybe it shouldn't be possible to hit this case now that we MakeDir the actually dir... + perror(Topics.Path); return RC_ERROR_FILE; } } @@ -1664,6 +1686,7 @@ PrintUsage(char *BinaryLocation, config *DefaultConfig) " Override default root directory (\"%s\")\n" " -R \n" " Override default root URL (\"%s\")\n" + " \e[1;31mIMPORTANT\e[0m: -r and -R must correspond to the same location\n" " -c \n" " Override default CSS directory (\"%s\"), relative to root\n" " -i \n" @@ -4165,9 +4188,9 @@ MonitorDirectory(buffers *CollationBuffers, template *IndexTemplate, template *P fclose(MemLog); #endif - // TODO(matt): Maybe straight up store the IndexPath in the Config to save us having to derive it near / at the usage site buffer Events; - if(ClaimBuffer(&Events, "inotify Events", Kilobytes(32)) == RC_ARENA_FULL) { return RC_ARENA_FULL; }; + // TODO(matt): Figure out the max size necessary for the Events buffer + if(ClaimBuffer(&Events, "inotify Events", Kilobytes(1024)) == RC_ARENA_FULL) { return RC_ARENA_FULL; }; struct inotify_event *Event; int BytesRead; @@ -4860,6 +4883,7 @@ main(int ArgC, char **Args) } NextFile: + // TODO(matt): Just change the default output location so all these guys won't overwrite each other for(int FileIndex = optind; FileIndex < ArgC; ++FileIndex) { switch(HMMLToBuffers(&CollationBuffers, Args[FileIndex]))