[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-4' - ios/Mobile

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Apr 26 07:47:50 UTC 2019


 ios/Mobile/AppDelegate.mm |   83 +++++++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 40 deletions(-)

New commits:
commit 645c3f6e6ecd4ef5afb107ed9061c30b05332b90
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Fri Apr 26 10:46:12 2019 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Fri Apr 26 10:47:22 2019 +0300

    tdf#124918: Allow empty lines in the template list file

diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm
index b67caf194..aa9737cae 100644
--- a/ios/Mobile/AppDelegate.mm
+++ b/ios/Mobile/AppDelegate.mm
@@ -89,47 +89,50 @@ static void updateTemplates(NSData *data, NSURLResponse *response)
         // Allow comment lines staring with a hash sign.
         if (*p != '#') {
             const int length = endOfLine - p;
-            std::vector<char> buf(length+1);
-            std::memcpy(buf.data(), p, length);
-            buf[length] = 0;
-
-            NSString *line = [NSString stringWithUTF8String:buf.data()];
-
-            NSURL *url = [NSURL URLWithString:line];
-            NSString *baseName = [url lastPathComponent];
-
-            NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0];
-            [urlHashes addObject:hash];
-
-            NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash];
-
-            NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]];
-
-            // If we have that template, check whether it is up-to-date
-            BOOL isDirectory;
-            if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] &&
-                isDirectory) {
-                NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy];
-                [req setHTTPMethod:@"HEAD"];
-                [[[NSURLSession sharedSession] dataTaskWithRequest:req
-                                                 completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
-                            if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) {
-                                NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"];
-                                NSDateFormatter *df = [[NSDateFormatter alloc] init];
-                                df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
-                                NSDate *templateDate = [df dateFromString:lastModified];
-
-                                NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate];
-
-                                if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) {
-                                    downloadTemplate(url, fileForTemplate);
+            // Allow empty lines
+            if (length > 0) {
+                std::vector<char> buf(length+1);
+                std::memcpy(buf.data(), p, length);
+                buf[length] = 0;
+
+                NSString *line = [NSString stringWithUTF8String:buf.data()];
+
+                NSURL *url = [NSURL URLWithString:line];
+                NSString *baseName = [url lastPathComponent];
+
+                NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0];
+                [urlHashes addObject:hash];
+
+                NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash];
+
+                NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]];
+
+                // If we have that template, check whether it is up-to-date
+                BOOL isDirectory;
+                if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] &&
+                    isDirectory) {
+                    NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy];
+                    [req setHTTPMethod:@"HEAD"];
+                    [[[NSURLSession sharedSession] dataTaskWithRequest:req
+                                                     completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
+                                if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) {
+                                    NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"];
+                                    NSDateFormatter *df = [[NSDateFormatter alloc] init];
+                                    df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
+                                    NSDate *templateDate = [df dateFromString:lastModified];
+
+                                    NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate];
+
+                                    if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) {
+                                        downloadTemplate(url, fileForTemplate);
+                                    }
                                 }
-                            }
-                        }] resume];
-            } else {
-                // Else download it.
-                [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil];
-                downloadTemplate(url, fileForTemplate);
+                            }] resume];
+                } else {
+                    // Else download it.
+                    [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil];
+                    downloadTemplate(url, fileForTemplate);
+                }
             }
         }
         if (endOfLine < endOfData)


More information about the Libreoffice-commits mailing list