Skip to content

Commit e5e30d4

Browse files
committed
- OCCore: replace directly defined completionHandler blocks with typedef variants, also accept omission for -updateDrive:…
- OCVault+TemporaryTools: new OCVault methods to simplify temporary saving of files
1 parent 44002fd commit e5e30d4

File tree

8 files changed

+147
-9
lines changed

8 files changed

+147
-9
lines changed

ownCloudSDK.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@
181181
DC2D646821C3D71000EB26FD /* OCCore+Thumbnails.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2D646721C3D70F00EB26FD /* OCCore+Thumbnails.h */; };
182182
DC2D649C21C7B3DF00EB26FD /* OCAuthenticationMethodOAuth2+OCMocking.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2D649A21C7B3DF00EB26FD /* OCAuthenticationMethodOAuth2+OCMocking.h */; settings = {ATTRIBUTES = (Public, ); }; };
183183
DC2D649D21C7B3DF00EB26FD /* OCAuthenticationMethodOAuth2+OCMocking.m in Sources */ = {isa = PBXBuildFile; fileRef = DC2D649B21C7B3DF00EB26FD /* OCAuthenticationMethodOAuth2+OCMocking.m */; };
184+
DC2EB43F2D6FBB4400100A67 /* OCVault+TemporaryTools.m in Sources */ = {isa = PBXBuildFile; fileRef = DC2EB43E2D6FBB4400100A67 /* OCVault+TemporaryTools.m */; };
185+
DC2EB4402D6FBB4400100A67 /* OCVault+TemporaryTools.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2EB43D2D6FBB4400100A67 /* OCVault+TemporaryTools.h */; settings = {ATTRIBUTES = (Public, ); }; };
184186
DC2F63632239455E0063C2DA /* OCRecipientSearchController.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2F63612239455E0063C2DA /* OCRecipientSearchController.h */; settings = {ATTRIBUTES = (Public, ); }; };
185187
DC2F63642239455E0063C2DA /* OCRecipientSearchController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC2F63622239455E0063C2DA /* OCRecipientSearchController.m */; };
186188
DC2F63682239509E0063C2DA /* OCCore+Sharing.m in Sources */ = {isa = PBXBuildFile; fileRef = DC2F63662239509E0063C2DA /* OCCore+Sharing.m */; };
@@ -1276,6 +1278,8 @@
12761278
DC2D646721C3D70F00EB26FD /* OCCore+Thumbnails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "OCCore+Thumbnails.h"; sourceTree = "<group>"; };
12771279
DC2D649A21C7B3DF00EB26FD /* OCAuthenticationMethodOAuth2+OCMocking.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCAuthenticationMethodOAuth2+OCMocking.h"; sourceTree = "<group>"; };
12781280
DC2D649B21C7B3DF00EB26FD /* OCAuthenticationMethodOAuth2+OCMocking.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCAuthenticationMethodOAuth2+OCMocking.m"; sourceTree = "<group>"; };
1281+
DC2EB43D2D6FBB4400100A67 /* OCVault+TemporaryTools.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCVault+TemporaryTools.h"; sourceTree = "<group>"; };
1282+
DC2EB43E2D6FBB4400100A67 /* OCVault+TemporaryTools.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCVault+TemporaryTools.m"; sourceTree = "<group>"; };
12791283
DC2F63612239455E0063C2DA /* OCRecipientSearchController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCRecipientSearchController.h; sourceTree = "<group>"; };
12801284
DC2F63622239455E0063C2DA /* OCRecipientSearchController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCRecipientSearchController.m; sourceTree = "<group>"; };
12811285
DC2F63662239509E0063C2DA /* OCCore+Sharing.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCCore+Sharing.m"; sourceTree = "<group>"; };
@@ -3664,6 +3668,8 @@
36643668
DC82665D2818972200F91F7D /* OCVaultLocation.h */,
36653669
DCB4F6E628324A3A005AD181 /* OCVaultDriveList.m */,
36663670
DCB4F6E528324A3A005AD181 /* OCVaultDriveList.h */,
3671+
DC2EB43E2D6FBB4400100A67 /* OCVault+TemporaryTools.m */,
3672+
DC2EB43D2D6FBB4400100A67 /* OCVault+TemporaryTools.h */,
36673673
DC22669922817DC600FB29EE /* OCVault+Internal.m */,
36683674
DC22669822817DC600FB29EE /* OCVault+Internal.h */,
36693675
DCCE49312684B0EF005961D8 /* Prepopulation */,
@@ -4869,6 +4875,7 @@
48694875
DCCC85912CF87C8200251683 /* GAGraphStruct+Encoder.h in Headers */,
48704876
DC70147F220B0650009D4FD9 /* OCHTTPResponse.h in Headers */,
48714877
DCC8F9F6202855A200EB6701 /* OCShare.h in Headers */,
4878+
DC2EB4402D6FBB4400100A67 /* OCVault+TemporaryTools.h in Headers */,
48724879
DC47E4E827A5820D0020E8EF /* GAFolderView.h in Headers */,
48734880
DC27BBC32304A7CE002CC2F8 /* NSHTTPCookie+OCCookies.h in Headers */,
48744881
DCA35D6124CF704100DBE2B0 /* OCSyncAction+Diagnostic.h in Headers */,
@@ -5615,6 +5622,7 @@
56155622
DC62FD63211B11FD0034B628 /* OCItem+OCThumbnail.m in Sources */,
56165623
DCEEB2DD20430B1400189B9A /* NSURL+OCURLQueryParameterExtensions.m in Sources */,
56175624
DC47E4CC27A5820D0020E8EF /* GAFileSystemInfo.m in Sources */,
5625+
DC2EB43F2D6FBB4400100A67 /* OCVault+TemporaryTools.m in Sources */,
56185626
DC2F6376223A61990063C2DA /* OCCoreQuery.m in Sources */,
56195627
DCC8F9F7202855A200EB6701 /* OCShare.m in Sources */,
56205628
DC0CE19728C8907D009ABDFB /* OCResourceRequestURLItem.m in Sources */,

ownCloudSDK/Core/DriveManagement/OCCore+DriveManagement.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ - (nullable NSProgress *)updateDrive:(OCDrive *)drive properties:(NSDictionary<O
7575
if (error == nil) {
7676
[self fetchUpdatesWithCompletionHandler:nil];
7777
}
78-
completionHandler(error, newDrive);
78+
if (completionHandler != nil) {
79+
completionHandler(error, newDrive);
80+
}
7981
}]);
8082
}
8183

82-
- (void)retrieveDrive:(OCDrive *)drive itemForResource:(OCDriveResource)resource completionHandler:(void(^)(NSError * _Nullable error, OCItem * _Nullable item))completionHandler
84+
- (void)retrieveDrive:(OCDrive *)drive itemForResource:(OCDriveResource)resource completionHandler:(nonnull OCCoreItemCompletionHandler)completionHandler
8385
{
84-
NSError *error = nil;
8586
GADriveItem *driveItem = nil;
8687

8788
if ([resource isEqual:OCDriveResourceCoverImage]) {
@@ -178,13 +179,15 @@ - (void)retrieveDrive:(OCDrive *)drive itemForResource:(OCDriveResource)resource
178179
}
179180
}
180181

181-
- (nullable NSProgress *)updateDrive:(OCDrive *)drive resourceFor:(OCDriveResource)resource withItem:(nullable OCItem *)item completionHandler:(void(^)(NSError * _Nullable error, OCDrive * _Nullable drive))completionHandler
182+
- (nullable NSProgress *)updateDrive:(OCDrive *)drive resourceFor:(OCDriveResource)resource withItem:(nullable OCItem *)item completionHandler:(nullable OCCoreDriveCompletionHandler)completionHandler
182183
{
183184
return ([self.connection updateDrive:drive resourceFor:resource withItem:item completionHandler:^(NSError * _Nullable error, OCDrive * _Nullable drive) {
184185
if (error == nil) {
185186
[self fetchUpdatesWithCompletionHandler:nil];
186187
}
187-
completionHandler(error, drive);
188+
if (completionHandler != nil) {
189+
completionHandler(error, drive);
190+
}
188191
}]);
189192
}
190193

ownCloudSDK/Core/OCCore.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ typedef void(^OCCoreClaimCompletionHandler)(NSError * _Nullable error, OCItem *
118118
typedef void(^OCCoreCompletionHandler)(NSError * _Nullable error);
119119
typedef void(^OCCoreStateChangedHandler)(OCCore *core);
120120
typedef void(^OCCoreSyncReasonCountChangeObserver)(OCCore *core, BOOL initial, NSDictionary<OCSyncReason, NSNumber *> * _Nullable countBySyncReason);
121-
typedef void(^OCCoreDriveCompletionHandler)(NSError * _Nullable error, OCDrive * _Nullable newDrive);
121+
typedef void(^OCCoreDriveCompletionHandler)(NSError * _Nullable error, OCDrive * _Nullable drive);
122+
typedef void(^OCCoreItemCompletionHandler)(NSError * _Nullable error, OCItem * _Nullable item);
123+
122124

123125
typedef void(^OCCoreBusyStatusHandler)(NSProgress * _Nullable progress);
124126

@@ -524,10 +526,10 @@ typedef void(^OCCoreShareRoleRetrievalHandler)(NSError * _Nullable error, NSArra
524526
- (nullable NSProgress *)deleteDrive:(OCDrive *)drive completionHandler:(OCCoreCompletionHandler)completionHandler;
525527

526528
// Change attributes
527-
- (nullable NSProgress *)updateDrive:(OCDrive *)drive properties:(NSDictionary<OCDriveProperty, id> *)updateProperties completionHandler:(OCCoreDriveCompletionHandler)completionHandler;
529+
- (nullable NSProgress *)updateDrive:(OCDrive *)drive properties:(NSDictionary<OCDriveProperty, id> *)updateProperties completionHandler:(nullable OCCoreDriveCompletionHandler)completionHandler;
528530

529-
- (void)retrieveDrive:(OCDrive *)drive itemForResource:(OCDriveResource)resource completionHandler:(void(^)(NSError * _Nullable error, OCItem * _Nullable item))completionHandler;
530-
- (nullable NSProgress *)updateDrive:(OCDrive *)drive resourceFor:(OCDriveResource)resource withItem:(nullable OCItem *)item completionHandler:(void(^)(NSError * _Nullable error, OCDrive * _Nullable drive))completionHandler;
531+
- (void)retrieveDrive:(OCDrive *)drive itemForResource:(OCDriveResource)resource completionHandler:(OCCoreItemCompletionHandler)completionHandler;
532+
- (nullable NSProgress *)updateDrive:(OCDrive *)drive resourceFor:(OCDriveResource)resource withItem:(nullable OCItem *)item completionHandler:(nullable OCCoreDriveCompletionHandler)completionHandler;
531533

532534
@end
533535

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// OCVault+TemporaryTools.h
3+
// ownCloudSDK
4+
//
5+
// Created by Felix Schwarz on 26.02.25.
6+
// Copyright © 2025 ownCloud GmbH. All rights reserved.
7+
//
8+
9+
/*
10+
* Copyright (C) 2025, ownCloud GmbH.
11+
*
12+
* This code is covered by the GNU Public License Version 3.
13+
*
14+
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
15+
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
16+
*
17+
*/
18+
19+
#import "OCVault.h"
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
typedef void(^OCVaultTemporaryStorageEraser)(void); //!< Block that, if called, deletes the temporarily allocated filesystem object(s).
24+
25+
@interface OCVault (TemporaryTools)
26+
27+
- (nullable OCVaultTemporaryStorageEraser)createTemporaryUploadContainer:(out NSURL * _Nullable * _Nullable)outURL error:(out NSError * _Nullable * _Nullable)outError; //!< Create a temporary folder in the .temporaryUploadURL of the vault, returning a block to delete it.
28+
- (nullable OCVaultTemporaryStorageEraser)createTemporaryUploadFileFromData:(NSData *)data name:(NSString *)name url:(out NSURL * _Nullable * _Nullable)outURL error:(out NSError * _Nullable * _Nullable)outError; //!< Creates a temporary folder with a temporary file inside, containing the passed data. Returns a block to delete the temporary folder + file.
29+
30+
@end
31+
32+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// OCVault+TemporaryTools.m
3+
// ownCloudSDK
4+
//
5+
// Created by Felix Schwarz on 26.02.25.
6+
// Copyright © 2025 ownCloud GmbH. All rights reserved.
7+
//
8+
9+
/*
10+
* Copyright (C) 2025, ownCloud GmbH.
11+
*
12+
* This code is covered by the GNU Public License Version 3.
13+
*
14+
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
15+
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
16+
*
17+
*/
18+
19+
#import "OCVault+TemporaryTools.h"
20+
21+
@implementation OCVault (TemporaryTools)
22+
23+
- (nullable OCVaultTemporaryStorageEraser)createTemporaryUploadContainer:(NSURL ** _Nullable)outURL error:(NSError * _Nullable * _Nullable)outError
24+
{
25+
NSURL *parentURL = self.temporaryUploadURL;
26+
NSURL *temporaryDirectoryURL = [parentURL URLByAppendingPathComponent:NSUUID.UUID.UUIDString];
27+
NSError *error = nil;
28+
OCVaultTemporaryStorageEraser eraser = nil;
29+
30+
if ([NSFileManager.defaultManager createDirectoryAtURL:temporaryDirectoryURL withIntermediateDirectories:YES attributes:@{ NSFileProtectionKey : NSFileProtectionCompleteUntilFirstUserAuthentication } error:&error])
31+
{
32+
eraser = ^{
33+
[NSFileManager.defaultManager removeItemAtURL:temporaryDirectoryURL error:NULL];
34+
};
35+
}
36+
37+
if (outURL != NULL) {
38+
*outURL = (error == nil) ? temporaryDirectoryURL : nil;
39+
}
40+
41+
if (outError != NULL) {
42+
*outError = error;
43+
}
44+
45+
return ([eraser copy]);
46+
}
47+
48+
- (nullable OCVaultTemporaryStorageEraser)createTemporaryUploadFileFromData:(NSData *)data name:(NSString *)name url:(NSURL * _Nonnull * _Nullable)outURL error:(NSError * _Nullable * _Nullable)outError
49+
{
50+
NSURL *containerURL = nil;
51+
NSError *error = nil;
52+
OCVaultTemporaryStorageEraser tempFolderEraser;
53+
OCVaultTemporaryStorageEraser eraser = nil;
54+
55+
if ((tempFolderEraser = [self createTemporaryUploadContainer:&containerURL error:&error]) != nil)
56+
{
57+
NSURL *tempFileURL = [containerURL URLByAppendingPathComponent:name];
58+
if ([data writeToURL:tempFileURL options:NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication error:&error])
59+
{
60+
if (outURL != NULL) {
61+
*outURL = tempFileURL;
62+
}
63+
eraser = tempFolderEraser;
64+
}
65+
else
66+
{
67+
tempFolderEraser();
68+
}
69+
}
70+
71+
if (outError != NULL) {
72+
*outError = error;
73+
}
74+
75+
return (eraser);
76+
}
77+
78+
@end

ownCloudSDK/Vaults/OCVault.h

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"TemporaryDownloads"/ - OCVault.temporaryDownloadURL
5555
[Random UUID] (temporary files for downloads)
5656
57+
"TemporaryUploads"/ - OCVault.temporaryUploadURL
58+
[Random UUID] (temporary files for uploads)
5759
5860
"messageQueue.dat" - OCMessageQueue.globalQueue KVS
5961
@@ -104,6 +106,7 @@ typedef BOOL(^OCVaultCompactSelector)(OCSyncAnchor _Nullable syncAnchor, OCItem
104106
NSURL *_filesRootURL;
105107
NSURL *_httpPipelineRootURL;
106108
NSURL *_temporaryDownloadURL;
109+
NSURL *_temporaryUploadURL;
107110
NSURL *_bookmarkMetadataURL;
108111
NSURL *_wipeContainerRootURL;
109112
NSURL *_wipeContainerFilesRootURL;
@@ -144,6 +147,7 @@ typedef BOOL(^OCVaultCompactSelector)(OCSyncAnchor _Nullable syncAnchor, OCItem
144147
@property(nullable,readonly,nonatomic) NSURL *drivesRootURL; //!< The vault's root URL for drive folders
145148
@property(nullable,readonly,nonatomic) NSURL *httpPipelineRootURL; //!< The vault's root URL for HTTP pipeline data
146149
@property(nullable,readonly,nonatomic) NSURL *temporaryDownloadURL; //!< The vault's root URL for temporarily downloaded files.
150+
@property(nullable,readonly,nonatomic) NSURL *temporaryUploadURL; //!< The vault's root URL for temporary files for uploading.
147151
@property(nullable,readonly,nonatomic) NSURL *bookmarkMetadataURL; //!< The vault's root URL for bookmark metadata files.
148152

149153
@property(nullable,readonly,nonatomic) NSURL *wipeContainerRootURL; //!< The vault's rootURL subfolder for items to erase.

ownCloudSDK/Vaults/OCVault.m

+10
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ - (NSURL *)temporaryDownloadURL
280280
return (_temporaryDownloadURL);
281281
}
282282

283+
- (NSURL *)temporaryUploadURL
284+
{
285+
if (_temporaryUploadURL == nil)
286+
{
287+
_temporaryUploadURL = [self.rootURL URLByAppendingPathComponent:@"TemporaryUploads"];
288+
}
289+
290+
return (_temporaryUploadURL);
291+
}
292+
283293
- (NSURL *)bookmarkMetadataURL
284294
{
285295
if (_bookmarkMetadataURL == nil)

ownCloudSDK/ownCloudSDK.h

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ FOUNDATION_EXPORT const unsigned char ownCloudSDKVersionString[];
161161
#import <ownCloudSDK/OCEventTarget.h>
162162

163163
#import <ownCloudSDK/OCVault.h>
164+
#import <ownCloudSDK/OCVault+TemporaryTools.h>
164165
#import <ownCloudSDK/OCVaultLocation.h>
165166
#import <ownCloudSDK/OCDatabase.h>
166167
#import <ownCloudSDK/OCDatabase+Versions.h>

0 commit comments

Comments
 (0)