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:
Jean Raby
2012-12-10 14:05:11 -05:00
parent b4822f6c4e
commit a0aef043a8
+27 -7
View File
@@ -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);
}
}
}
}