ios/Mobile/AppDelegate.mm |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

New commits:
commit 377e9266c9cd18de3e39032f79f9d2d544b72e7b
Author:     Tor Lillqvist <t...@collabora.com>
AuthorDate: Thu Jul 23 19:11:29 2020 +0300
Commit:     Tor Lillqvist <t...@collabora.com>
CommitDate: Thu Jul 23 19:18:55 2020 +0300

    tdf#134832: Clear the cache directory if it is for another version of the 
app
    
    We don't want to use cached scaled icons (and other stuff that might
    be in the cache?) if from a potentially incompatible version of the
    app. Store the core and online hashes in files in the cache to be able
    to compare.
    
    Change-Id: I593ece5dae71f91f204d4c040bd9f744b3bc498f

diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm
index d6962b840..207d59393 100644
--- a/ios/Mobile/AppDelegate.mm
+++ b/ios/Mobile/AppDelegate.mm
@@ -191,6 +191,37 @@ static void updateTemplates(NSData *data, NSURLResponse 
*response)
     Log::initialize("Mobile", trace, false, false, {});
     Util::setThreadName("main");
 
+    // Clear the cache directory if it is for another build of the app
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
NSUserDomainMask, YES);
+    NSString *userDirectory = [paths objectAtIndex:0];
+    NSString *cacheDirectory = [userDirectory 
stringByAppendingPathComponent:@"cache"];
+
+    NSString *coreVersionHashFile = [cacheDirectory 
stringByAppendingPathComponent:@"core_version_hash"];
+    NSString *loolwsdVersionHashFile = [cacheDirectory 
stringByAppendingPathComponent:@"loolwsd_version_hash"];
+
+    NSData *oldCoreVersionHash = [NSData 
dataWithContentsOfFile:coreVersionHashFile];
+    NSData *oldLoolwsdVersionHash = [NSData 
dataWithContentsOfFile:loolwsdVersionHashFile];
+
+    NSData *coreVersionHash = [NSData dataWithBytes:CORE_VERSION_HASH 
length:strlen(CORE_VERSION_HASH)];
+    NSData *loolwsdVersionHash = [NSData dataWithBytes:LOOLWSD_VERSION_HASH 
length:strlen(LOOLWSD_VERSION_HASH)];
+
+    if (oldCoreVersionHash == nil
+        || ![oldCoreVersionHash isEqualToData:coreVersionHash]
+        || oldLoolwsdVersionHash == nil
+        || ![oldLoolwsdVersionHash isEqualToData:loolwsdVersionHash]) {
+
+        [[NSFileManager defaultManager] removeItemAtPath:cacheDirectory 
error:nil];
+
+        if (![[NSFileManager defaultManager] 
createDirectoryAtPath:cacheDirectory withIntermediateDirectories:NO 
attributes:nil error:nil])
+            NSLog(@"Could not create %@", cacheDirectory);
+
+        if (![[NSFileManager defaultManager] 
createFileAtPath:coreVersionHashFile contents:coreVersionHash attributes:nil])
+            NSLog(@"Could not create %@", coreVersionHashFile);
+
+        if (![[NSFileManager defaultManager] 
createFileAtPath:loolwsdVersionHashFile contents:loolwsdVersionHash 
attributes:nil])
+            NSLog(@"Could not create %@", loolwsdVersionHashFile);
+    }
+
     // Having LANG in the environment is expected to happen only when 
debugging from Xcode. When
     // testing some language one doesn't know it might be risky to simply set 
one's iPad to that
     // language, as it might be hard to find the way to set it back to a known 
language.
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to