mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-21 11:25:24 +00:00
Don't abort if sogo.conf exists and is empty
This will permit patterns like: sogo-tool dump-defaults >/etc/sogo/sogo.conf Without this, sogo-tool would abort as the shell first creates the file then executes sogo-tool.
This commit is contained in:
@@ -87,20 +87,40 @@ static void
|
||||
_injectConfigurationFromFile (NSUserDefaults *ud,
|
||||
NSString *filename, NSObject *logger)
|
||||
{
|
||||
NSDictionary *newConfig,*fileAttrs;
|
||||
NSError *fmError = nil;
|
||||
NSFileManager *fm;
|
||||
NSDictionary *newConfig;
|
||||
|
||||
fm = [NSFileManager defaultManager];
|
||||
if ([fm fileExistsAtPath: filename])
|
||||
{
|
||||
newConfig = [NSDictionary dictionaryWithContentsOfFile: filename];
|
||||
if (newConfig)
|
||||
[ud registerDefaults: newConfig];
|
||||
fileAttrs = [fm attributesOfItemAtPath: filename
|
||||
error: &fmError];
|
||||
if (![fileAttrs objectForKey: @"NSFileSize"])
|
||||
{
|
||||
[logger errorWithFormat:
|
||||
@"Can't get file attributes from '%@': %@",
|
||||
filename, [fmError description]];
|
||||
exit(1);
|
||||
}
|
||||
if ([[fileAttrs objectForKey: @"NSFileSize"] intValue] == 0 )
|
||||
{
|
||||
[logger warnWithFormat:
|
||||
@"Empty file: '%@'. Skipping",
|
||||
filename];
|
||||
}
|
||||
else
|
||||
{
|
||||
[logger errorWithFormat: @"Cannot read configuration from '%@'.",
|
||||
filename];
|
||||
exit (1);
|
||||
newConfig = [NSDictionary dictionaryWithContentsOfFile: filename];
|
||||
if (newConfig)
|
||||
[ud registerDefaults: newConfig];
|
||||
else
|
||||
{
|
||||
[logger errorWithFormat:
|
||||
@"Cannot read configuration from '%@'. Aborting",
|
||||
filename];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user