Skip to content

Commit

Permalink
Merge pull request #5903 from nextcloud/bugfix/fix-findersyncext
Browse files Browse the repository at this point in the history
Fix Finder Sync Extension
  • Loading branch information
claucambra committed Jul 24, 2023
2 parents 03bfbbf + 1e9dbf8 commit a727971
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ else()
unset(CMAKE_CXX_CLANG_TIDY)
endif()

if (APPLE)
# build macOS File Provider module
option(BUILD_FILE_PROVIDER_MODULE "BUILD_FILE_PROVIDER_MODULE" OFF)
endif()

# When this option is enabled, 5xx errors are not added to the blacklist
# Normally you don't want to enable this option because if a particular file
# triggers a bug on the server, you want the file to be blacklisted.
Expand Down
2 changes: 1 addition & 1 deletion NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ if(WIN32)
endif()

if (APPLE)
set( BUILD_FILE_PROVIDER_MODULE OFF )
option( BUILD_FILE_PROVIDER_MODULE "Build the macOS virtual files File Provider module" OFF )
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
#import "FinderSyncSocketLineProcessor.h"

@interface FinderSync : FIFinderSync <SyncClientDelegate>
{
NSMutableSet *_registeredDirectories;
NSString *_shareMenuTitle;
NSMutableDictionary *_strings;
NSMutableArray *_menuItems;
NSCondition *_menuIsComplete;
}

@property FinderSyncSocketLineProcessor *lineProcessor;
@property LocalSocketClient *localSocketClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@

#import "FinderSync.h"

@interface FinderSync()
{
NSMutableSet *_registeredDirectories;
NSString *_shareMenuTitle;
NSMutableDictionary *_strings;
NSMutableArray *_menuItems;
NSCondition *_menuIsComplete;
}
@end

@implementation FinderSync

Expand Down Expand Up @@ -71,6 +80,10 @@ - (instancetype)init
NSLog(@"No socket path. Not initiating local socket client.");
self.localSocketClient = nil;
}

_registeredDirectories = NSMutableSet.set;
_strings = NSMutableDictionary.dictionary;
_menuIsComplete = [[NSCondition alloc] init];
}

return self;
Expand Down Expand Up @@ -194,7 +207,7 @@ - (void)reFetchFileNameCacheForPath:(NSString*)path

- (void)registerPath:(NSString*)path
{
assert(_registeredDirectories);
NSAssert(_registeredDirectories, @"Registered directories should be a valid set!");
[_registeredDirectories addObject:[NSURL fileURLWithPath:path]];
[FIFinderSyncController defaultController].directoryURLs = _registeredDirectories;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ -(instancetype)initWithDelegate:(id<SyncClientDelegate>)delegate

-(void)process:(NSString*)line
{
NSLog(@"Processing line: %@", line);
NSLog(@"Processing line: '%@'", line);
NSArray *split = [line componentsSeparatedByString:@":"];
NSString *command = [split objectAtIndex:0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,24 +326,42 @@ - (void)readFromSocket

- (void)processInBuffer
{
NSLog(@"Processing in buffer. In buffer length %li", [_inBuffer length]);
UInt8 separator[] = {0xa}; // Byte value for "\n"
while(true) {
NSRange firstSeparatorIndex = [_inBuffer rangeOfData:[NSData dataWithBytes:separator length:1] options:0 range:NSMakeRange(0, [_inBuffer length])];

if(firstSeparatorIndex.location == NSNotFound) {
NSLog(@"No separator found. Stopping.");
return; // No separator, nope out
} else {
unsigned char *buffer = [_inBuffer mutableBytes];
buffer[firstSeparatorIndex.location] = 0; // Add NULL terminator, so we can use C string methods

NSString *newLine = [NSString stringWithUTF8String:[_inBuffer bytes]];
NSLog(@"Processing in buffer. In buffer length %li", _inBuffer.length);

static const UInt8 separator[] = {0xa}; // Byte value for "\n"
static const char terminator[] = {0};
NSData * const separatorData = [NSData dataWithBytes:separator length:1];

while(_inBuffer.length > 0) {
const NSUInteger inBufferLength = _inBuffer.length;
const NSRange inBufferLengthRange = NSMakeRange(0, inBufferLength);
const NSRange firstSeparatorIndex = [_inBuffer rangeOfData:separatorData
options:0
range:inBufferLengthRange];

NSUInteger nullTerminatorIndex = NSUIntegerMax;

[_inBuffer replaceBytesInRange:NSMakeRange(0, firstSeparatorIndex.location + 1) withBytes:NULL length:0];
[_lineProcessor process:newLine];
// Add NULL terminator, so we can use C string methods
if (firstSeparatorIndex.location == NSNotFound) {
NSLog(@"No separator found. Creating new buffer qith space for null terminator.");

[_inBuffer appendBytes:terminator length:1];
nullTerminatorIndex = inBufferLength;
} else {
nullTerminatorIndex = firstSeparatorIndex.location;
[_inBuffer replaceBytesInRange:NSMakeRange(nullTerminatorIndex, 1) withBytes:terminator];
}

NSAssert(nullTerminatorIndex != NSUIntegerMax, @"Null terminator index should be valid.");

NSString * const newLine = [NSString stringWithUTF8String:_inBuffer.bytes];
const NSRange nullTerminatorRange = NSMakeRange(0, nullTerminatorIndex + 1);

[_inBuffer replaceBytesInRange:nullTerminatorRange withBytes:NULL length:0];
[_lineProcessor process:newLine];
}

NSLog(@"Finished processing inBuffer");
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = FinderSyncExt/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -1151,7 +1150,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = FinderSyncExt/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down

0 comments on commit a727971

Please sign in to comment.