From a0aef043a8fe2bab442e8c01b172f731a13d531e Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Mon, 10 Dec 2012 14:05:11 -0500 Subject: [PATCH] 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. --- SoObjects/SOGo/SOGoSystemDefaults.m | 34 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m index 67101044f..3393c57f0 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.m +++ b/SoObjects/SOGo/SOGoSystemDefaults.m @@ -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); + } } } }