Leave usage as a property of materialised files enumerator

Do this instead of passing as variable in completion handler

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-09-28 17:48:47 +08:00
parent 02b47b47f8
commit 0b8a2315a0
No known key found for this signature in database
GPG key ID: C839200C384636B0
3 changed files with 14 additions and 16 deletions

View file

@ -196,9 +196,9 @@ private:
const id<NSFileProviderEnumerator> enumerator = [managerForDomain enumeratorForMaterializedItems];
Q_ASSERT(enumerator != nil);
FileProviderStorageUseEnumerationObserver *const storageUseObserver = [[FileProviderStorageUseEnumerationObserver alloc] init];
__block FileProviderStorageUseEnumerationObserver *const storageUseObserver = [[FileProviderStorageUseEnumerationObserver alloc] init];
storageUseObserver.enumerationFinishedHandler = ^(NSNumber *const usage, NSError *const error) {
storageUseObserver.enumerationFinishedHandler = ^(NSError *const error) {
if (error != nil) {
qCWarning(lcFileProviderSettingsController) << "Error while enumerating storage use" << error.localizedDescription;
[storageUseObserver release];
@ -206,16 +206,16 @@ private:
return;
}
Q_ASSERT(usage != nil);
const NSUInteger usage = storageUseObserver.usage;
// Remember that OCC::Account::userIdAtHost == domain.identifier for us
NSMutableDictionary<NSString *, NSNumber *> *const mutableStorageDictCopy = _storageUsage.mutableCopy;
qCDebug(lcFileProviderSettingsController) << "Local storage use for"
<< domain.identifier
<< usage.unsignedLongLongValue;
<< usage;
[mutableStorageDictCopy setObject:usage forKey:domain.identifier];
[mutableStorageDictCopy setObject:@(usage) forKey:domain.identifier];
_storageUsage = mutableStorageDictCopy.copy;
const auto qDomainIdentifier = QString::fromNSString(domain.identifier);

View file

@ -15,10 +15,11 @@
#import <Foundation/Foundation.h>
#import <FileProvider/FileProvider.h>
typedef void(^UsageEnumerationFinishedHandler)(NSNumber *const usage, NSError *const error);
typedef void(^UsageEnumerationFinishedHandler)(NSError *const error);
@interface FileProviderStorageUseEnumerationObserver : NSObject<NSFileProviderEnumerationObserver>
@property (readwrite, strong) UsageEnumerationFinishedHandler enumerationFinishedHandler;
@property (readonly) NSUInteger usage;
@end

View file

@ -14,11 +14,6 @@
#import "fileproviderstorageuseenumerationobserver.h"
@interface FileProviderStorageUseEnumerationObserver ()
@property (readwrite) NSUInteger usage;
@end
@implementation FileProviderStorageUseEnumerationObserver
@ -26,7 +21,7 @@
{
self = [super init];
if (self) {
self.usage = 0ULL;
_usage = 0ULL;
}
return self;
}
@ -35,22 +30,24 @@
- (void)didEnumerateItems:(NSArray<id<NSFileProviderItem>> *)updatedItems
{
for (const id<NSFileProviderItem> item in updatedItems) {
NSLog(@"StorageUseEnumerationObserver: Enumerating %@ with size %llu", item.filename, item.documentSize.unsignedLongLongValue);
self.usage += item.documentSize.unsignedLongLongValue;
NSLog(@"StorageUseEnumerationObserver: Enumerating %@ with size %llu",
item.filename, item.documentSize.unsignedLongLongValue);
_usage += item.documentSize.unsignedLongLongValue;
}
}
- (void)finishEnumeratingWithError:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
self.enumerationFinishedHandler(nil, error);
self.enumerationFinishedHandler(error);
});
}
- (void)finishEnumeratingUpToPage:(NSFileProviderPage)nextPage
{
dispatch_async(dispatch_get_main_queue(), ^{
self.enumerationFinishedHandler(@(self.usage), nil);
self.enumerationFinishedHandler(nil);
});
}