Просмотр исходного кода

Fix: Create default OSL directory

Tunnel core expects the obfuscated server list directory to pre-exist. So we need to make sure we create it.

Also updating the documentation to indicate that overridden directory values must pre-exist.
Adam Pritchard 9 лет назад
Родитель
Сommit
e3ab0cf07f

+ 3 - 2
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.h

@@ -56,8 +56,9 @@ FOUNDATION_EXPORT const unsigned char PsiphonTunnelVersionString[];
    - `ObfuscatedServerListRootURL`
 
  Optional fields (if you don't need them, don't set them):
- - `DataStoreDirectory`: If not set, the library will use a sane location. Override if the client wants to restrict where operational data is kept.
- - `RemoteServerListDownloadFilename`: See comment for `DataStoreDirectory`.
+ - `DataStoreDirectory`: If not set, the library will use a sane location. Override if the client wants to restrict where operational data is kept. If overridden, the directory must already exist and be writable.
+ - `RemoteServerListDownloadFilename`: If not set, the library will use a sane location. Override if the client wants to restrict where operational data is kept.
+ - `ObfuscatedServerListDownloadDirectory`: If not set, the library will use a sane location. Override if the client wants to restrict where operational data is kept. If overridden, the directory must already exist and be writable.
  - `ClientPlatform`: Should not be set by most library consumers.
  - `UpstreamProxyUrl`
  - `EmitDiagnosticNotices`

+ 26 - 8
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

@@ -183,6 +183,10 @@
         return nil;
     }
     
+    //
+    // DataStoreDirectory
+    //
+    
     // Some clients will have a data directory that they'd prefer the Psiphon
     // library use, but if not we'll default to the user Library directory.
     NSURL *defaultDataStoreDirectoryURL = [libraryURL URLByAppendingPathComponent:@"datastore" isDirectory:YES];
@@ -205,18 +209,16 @@
         [self logMessage:[NSString stringWithFormat: @"DataStoreDirectory overridden from '%@' to '%@'", [defaultDataStoreDirectoryURL path], config[@"DataStoreDirectory"]]];
     }
     
+    //
+    // Remote Server List
+    //
+    
     NSString *defaultRemoteServerListFilename = [[libraryURL URLByAppendingPathComponent:@"remote_server_list" isDirectory:NO] path];
     if (defaultRemoteServerListFilename == nil) {
         [self logMessage:@"Unable to create defaultRemoteServerListFilename"];
         return nil;
     }
     
-    NSString *defaultOSLDirectory = [[libraryURL URLByAppendingPathComponent:@"osl" isDirectory:YES] path];
-    if (defaultOSLDirectory == nil) {
-        [self logMessage:@"Unable to create defaultOSLDirectory"];
-        return nil;
-    }
-    
     if (config[@"RemoteServerListDownloadFilename"] == nil) {
         config[@"RemoteServerListDownloadFilename"] = defaultRemoteServerListFilename;
     }
@@ -231,11 +233,27 @@
         [self logMessage:@"Remote server list functionality will be disabled"];
     }
     
+    //
+    // Obfuscated Server List
+    //
+    
+    NSURL *defaultOSLDirectoryURL = [libraryURL URLByAppendingPathComponent:@"osl" isDirectory:YES];
+    if (defaultOSLDirectoryURL == nil) {
+        [self logMessage:@"Unable to create defaultOSLDirectory"];
+        return nil;
+    }
+    
     if (config[@"ObfuscatedServerListDownloadDirectory"] == nil) {
-        config[@"ObfuscatedServerListDownloadDirectory"] = defaultOSLDirectory;
+        [fileManager createDirectoryAtURL:defaultOSLDirectoryURL withIntermediateDirectories:YES attributes:nil error:&err];
+        if (err != nil) {
+            [self logMessage:[NSString stringWithFormat: @"Unable to create defaultOSLDirectoryURL: %@", err.localizedDescription]];
+            return nil;
+        }
+        
+        config[@"ObfuscatedServerListDownloadDirectory"] = [defaultOSLDirectoryURL path];
     }
     else {
-        [self logMessage:[NSString stringWithFormat: @"ObfuscatedServerListDownloadDirectory overridden from '%@' to '%@'", defaultOSLDirectory, config[@"ObfuscatedServerListDownloadDirectory"]]];
+        [self logMessage:[NSString stringWithFormat: @"ObfuscatedServerListDownloadDirectory overridden from '%@' to '%@'", [defaultOSLDirectoryURL path], config[@"ObfuscatedServerListDownloadDirectory"]]];
     }
     
     // If ObfuscatedServerListRootURL is absent, we'll leave it out, but log the absence.