cinera.c: Gracefully handle database non-creation
This commit is contained in:
parent
b3470e0f48
commit
6eeb588adf
|
@ -23,7 +23,7 @@ typedef struct
|
||||||
version CINERA_APP_VERSION = {
|
version CINERA_APP_VERSION = {
|
||||||
.Major = 0,
|
.Major = 0,
|
||||||
.Minor = 7,
|
.Minor = 7,
|
||||||
.Patch = 17
|
.Patch = 18
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <stdarg.h> // NOTE(matt): varargs
|
#include <stdarg.h> // NOTE(matt): varargs
|
||||||
|
@ -4735,7 +4735,6 @@ void *
|
||||||
LocateBlock(block_id BlockID)
|
LocateBlock(block_id BlockID)
|
||||||
{
|
{
|
||||||
void *Result = 0;
|
void *Result = 0;
|
||||||
|
|
||||||
db_header *Header = (db_header *)DB.Metadata.File.Buffer.Location;
|
db_header *Header = (db_header *)DB.Metadata.File.Buffer.Location;
|
||||||
char *Ptr = (char *)Header;
|
char *Ptr = (char *)Header;
|
||||||
Ptr += sizeof(db_header);
|
Ptr += sizeof(db_header);
|
||||||
|
@ -14133,9 +14132,10 @@ WriteEntireDatabase()
|
||||||
fclose(DB.Metadata.File.Handle);
|
fclose(DB.Metadata.File.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
rc
|
||||||
InitDB(void)
|
InitDB(void)
|
||||||
{
|
{
|
||||||
|
rc Result = RC_SUCCESS;
|
||||||
// TODO(matt): InitDB() is called once on startup. This is correct for the .metadata file, because we only want one of
|
// TODO(matt): InitDB() is called once on startup. This is correct for the .metadata file, because we only want one of
|
||||||
// those to house the info for all projects. However, we will want to create a .index file for each project, so
|
// those to house the info for all projects. However, we will want to create a .index file for each project, so
|
||||||
// need a separate InitIndex() function that we can call when looping over the projects after ParseConfig()
|
// need a separate InitIndex() function that we can call when looping over the projects after ParseConfig()
|
||||||
|
@ -14261,7 +14261,7 @@ InitDB(void)
|
||||||
LogError(LOG_ERROR, "Unable to create directory %.*s: %s", (int)Config->DatabaseLocation.Length, Config->DatabaseLocation.Base, strerror(errno));
|
LogError(LOG_ERROR, "Unable to create directory %.*s: %s", (int)Config->DatabaseLocation.Length, Config->DatabaseLocation.Base, strerror(errno));
|
||||||
fprintf(stderr, "Unable to create directory %.*s: %s\n", (int)Config->DatabaseLocation.Length, Config->DatabaseLocation.Base, strerror(errno));
|
fprintf(stderr, "Unable to create directory %.*s: %s\n", (int)Config->DatabaseLocation.Length, Config->DatabaseLocation.Base, strerror(errno));
|
||||||
Free(DatabaseLocation0);
|
Free(DatabaseLocation0);
|
||||||
return RC_ERROR_DIRECTORY;
|
Result = RC_ERROR_DIRECTORY;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -14271,6 +14271,9 @@ InitDB(void)
|
||||||
}
|
}
|
||||||
Free(DatabaseLocation0);
|
Free(DatabaseLocation0);
|
||||||
|
|
||||||
|
if(Result == RC_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
DB.Metadata.File.Handle = fopen(DB.Metadata.File.Path, "w");
|
DB.Metadata.File.Handle = fopen(DB.Metadata.File.Path, "w");
|
||||||
if(DB.Metadata.File.Handle)
|
if(DB.Metadata.File.Handle)
|
||||||
{
|
{
|
||||||
|
@ -14303,7 +14306,8 @@ InitDB(void)
|
||||||
ReadFileIntoBuffer(&DB.File);
|
ReadFileIntoBuffer(&DB.File);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return RC_SUCCESS;
|
}
|
||||||
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -15340,15 +15344,18 @@ PrintEvent(struct inotify_event *Event, int EventIndex, int Indentation)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
rc
|
||||||
InitAll(neighbourhood *Neighbourhood, buffers *CollationBuffers, template *BespokeTemplate)
|
InitAll(neighbourhood *Neighbourhood, buffers *CollationBuffers, template *BespokeTemplate)
|
||||||
{
|
{
|
||||||
|
rc Result = RC_SUCCESS;
|
||||||
MEM_TEST_TOP("InitAll()");
|
MEM_TEST_TOP("InitAll()");
|
||||||
RewindCollationBuffers(CollationBuffers);
|
RewindCollationBuffers(CollationBuffers);
|
||||||
/* */ MEM_TEST_MID("InitAll()");
|
/* */ MEM_TEST_MID("InitAll()");
|
||||||
/* +MEM */ InitDB();
|
/* +MEM */ Result = InitDB();
|
||||||
/* */ MEM_TEST_MID("InitAll()");
|
/* */ MEM_TEST_MID("InitAll()");
|
||||||
|
|
||||||
|
if(Result == RC_SUCCESS)
|
||||||
|
{
|
||||||
// TODO(matt): Straight up remove these PrintAssetsBlock() calls
|
// TODO(matt): Straight up remove these PrintAssetsBlock() calls
|
||||||
//PrintAssetsBlock(0);
|
//PrintAssetsBlock(0);
|
||||||
|
|
||||||
|
@ -15393,6 +15400,8 @@ InitAll(neighbourhood *Neighbourhood, buffers *CollationBuffers, template *Bespo
|
||||||
ColourStrings[EditTypes[EDIT_REINSERTION].Colour], ColourStrings[CS_END],
|
ColourStrings[EditTypes[EDIT_REINSERTION].Colour], ColourStrings[CS_END],
|
||||||
ColourStrings[EditTypes[EDIT_DELETION].Colour], ColourStrings[CS_END]);
|
ColourStrings[EditTypes[EDIT_DELETION].Colour], ColourStrings[CS_END]);
|
||||||
}
|
}
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RemoveAndFreeWatchHandles(watch_handles *W)
|
RemoveAndFreeWatchHandles(watch_handles *W)
|
||||||
|
@ -15672,6 +15681,7 @@ void
|
||||||
Exit(void)
|
Exit(void)
|
||||||
{
|
{
|
||||||
Free(MemoryArena.Location);
|
Free(MemoryArena.Location);
|
||||||
|
fprintf(stderr, "Exiting\n");
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15812,6 +15822,7 @@ main(int ArgC, char **Args)
|
||||||
PushWatchHandle(ConfigPathL, EXT_NULL, WT_CONFIG, 0, 0);
|
PushWatchHandle(ConfigPathL, EXT_NULL, WT_CONFIG, 0, 0);
|
||||||
|
|
||||||
Config = ParseConfig(ConfigPathL, &TokensList);
|
Config = ParseConfig(ConfigPathL, &TokensList);
|
||||||
|
rc Succeeding = RC_SUCCESS;
|
||||||
if(Config)
|
if(Config)
|
||||||
{
|
{
|
||||||
if(Mode & MODE_EXAMINE)
|
if(Mode & MODE_EXAMINE)
|
||||||
|
@ -15828,7 +15839,7 @@ main(int ArgC, char **Args)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* */ MEM_TEST_MID("main()");
|
/* */ MEM_TEST_MID("main()");
|
||||||
/* +MEM */ InitAll(&Neighbourhood, &CollationBuffers, &BespokeTemplate);
|
/* +MEM */ Succeeding = InitAll(&Neighbourhood, &CollationBuffers, &BespokeTemplate);
|
||||||
/* */ MEM_TEST_MID("main()");
|
/* */ MEM_TEST_MID("main()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15844,6 +15855,8 @@ main(int ArgC, char **Args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Succeeding == RC_SUCCESS)
|
||||||
|
{
|
||||||
if(inotifyInstance)
|
if(inotifyInstance)
|
||||||
{
|
{
|
||||||
while(MonitorFilesystem(&Neighbourhood, &CollationBuffers, &BespokeTemplate, ConfigPathL, &TokensList) != RC_ARENA_FULL)
|
while(MonitorFilesystem(&Neighbourhood, &CollationBuffers, &BespokeTemplate, ConfigPathL, &TokensList) != RC_ARENA_FULL)
|
||||||
|
@ -15875,5 +15888,6 @@ main(int ArgC, char **Args)
|
||||||
RemoveAndFreeWatchHandles(&WatchHandles);
|
RemoveAndFreeWatchHandles(&WatchHandles);
|
||||||
MEM_TEST_END("main()");
|
MEM_TEST_END("main()");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Exit();
|
Exit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue