From f194b05f0cad039123b6108e21bfc5f050228473 Mon Sep 17 00:00:00 2001 From: Thilo Molitor Date: Wed, 31 Jul 2024 19:43:57 +0200 Subject: [PATCH 1/2] Add setting to not link filetransfers into documents directory --- Monal/Classes/GeneralSettings.swift | 8 +++- Monal/Classes/MLFiletransfer.m | 61 +++++++++++++++-------------- Monal/Classes/MLXMPPManager.m | 2 + 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Monal/Classes/GeneralSettings.swift b/Monal/Classes/GeneralSettings.swift index 38929678b6..c4cdc771ef 100644 --- a/Monal/Classes/GeneralSettings.swift +++ b/Monal/Classes/GeneralSettings.swift @@ -118,6 +118,9 @@ class GeneralSettingsDefaultsDB: ObservableObject { @defaultsDB("uploadImagesOriginal") var uploadImagesOriginal: Bool + + @defaultsDB("hardlinkFiletransfersIntoDocuments") + var hardlinkFiletransfersIntoDocuments: Bool } @@ -457,7 +460,10 @@ struct AttachmentSettings: View { Form { Section(header: Text("General File Transfer Settings")) { SettingsToggle(isOn: $generalSettingsDefaultsDB.autodownloadFiletransfers) { - Text("Auto-Download Media") + Text("Auto-Download Media and Files") + } + SettingsToggle(isOn: $generalSettingsDefaultsDB.hardlinkFiletransfersIntoDocuments) { + Text("Make transfered Media and Files accessible in Files App") } } diff --git a/Monal/Classes/MLFiletransfer.m b/Monal/Classes/MLFiletransfer.m index 8a99d8f486..c9ed9a0541 100644 --- a/Monal/Classes/MLFiletransfer.m +++ b/Monal/Classes/MLFiletransfer.m @@ -358,12 +358,12 @@ -(void) URLSession:(nonnull NSURLSession*) session downloadTask:(nonnull NSURLSe if(error) { DDLogError(@"Could not copy cache file to tmp file: %@", error); - #ifdef DEBUG +#ifdef DEBUG @throw [NSException exceptionWithName:@"ERROR_WHILE_COPYING_CACHEFILE" reason:@"Could not copy cacheFile!" userInfo:@{ @"cacheFile": cacheFile, @"cacheFileTMP": cacheFileTMP }]; - #endif +#endif return; } @@ -371,11 +371,11 @@ -(void) URLSession:(nonnull NSURLSession*) session downloadTask:(nonnull NSURLSe if(error) { DDLogError(@"Could not delete original cache file: %@", error); - #ifdef DEBUG +#ifdef DEBUG @throw [NSException exceptionWithName:@"ERROR_WHILE_DELETING_CACHEFILE" reason:@"Could not delete cacheFile!" userInfo:@{ @"cacheFile": cacheFile }]; - #endif +#endif return; } @@ -383,42 +383,45 @@ -(void) URLSession:(nonnull NSURLSession*) session downloadTask:(nonnull NSURLSe if(error) { DDLogError(@"Could not rename tmp file to cache file: %@", error); - #ifdef DEBUG +#ifdef DEBUG @throw [NSException exceptionWithName:@"ERROR_WHILE_RENAMING_CACHEFILE" reason:@"Could not rename cacheFileTMP to cacheFile!" userInfo:@{ @"cacheFile": cacheFile, @"cacheFileTMP": cacheFileTMP }]; - #endif +#endif return; } } - NSURL* hardLink = [[_fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; - for(NSString* pathComponent in hardlinkPathComponents) - hardLink = [hardLink URLByAppendingPathComponent:pathComponent]; - - DDLogInfo(@"Hardlinking cache file at '%@' into documents directory at '%@'...", cacheFile, hardLink); - if(![_fileManager fileExistsAtPath:[hardLink.URLByDeletingLastPathComponent path]]) + if([[HelperTools defaultsDB] boolForKey:@"hardlinkFiletransfersIntoDocuments"]) { - DDLogVerbose(@"Creating hardlinking dir struct at '%@'...", hardLink.URLByDeletingLastPathComponent); - [_fileManager createDirectoryAtURL:hardLink.URLByDeletingLastPathComponent withIntermediateDirectories:YES attributes:@{NSFileProtectionKey: NSFileProtectionCompleteUntilFirstUserAuthentication} error:&error]; - if(error) - DDLogWarn(@"Ignoring error creating hardlinking dir struct at '%@': %@", hardLink, error); + NSURL* hardLink = [[_fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; + for(NSString* pathComponent in hardlinkPathComponents) + hardLink = [hardLink URLByAppendingPathComponent:pathComponent]; + + DDLogInfo(@"Hardlinking cache file at '%@' into documents directory at '%@'...", cacheFile, hardLink); + if(![_fileManager fileExistsAtPath:[hardLink.URLByDeletingLastPathComponent path]]) + { + DDLogVerbose(@"Creating hardlinking dir struct at '%@'...", hardLink.URLByDeletingLastPathComponent); + [_fileManager createDirectoryAtURL:hardLink.URLByDeletingLastPathComponent withIntermediateDirectories:YES attributes:@{NSFileProtectionKey: NSFileProtectionCompleteUntilFirstUserAuthentication} error:&error]; + if(error) + DDLogWarn(@"Ignoring error creating hardlinking dir struct at '%@': %@", hardLink, error); + else + [HelperTools configureFileProtection:NSFileProtectionCompleteUntilFirstUserAuthentication forFile:[hardLink path]]; + } + + //don't throw any error if the file aready exists, because it could be a rare collision (we only use 16 bit random numbers to keep the file prefix short) + if([_fileManager fileExistsAtPath:[hardLink path]]) + DDLogWarn(@"Not hardlinking file '%@' to '%@': file already exists (maybe a rare collision?)...", cacheFile, hardLink); else - [HelperTools configureFileProtection:NSFileProtectionCompleteUntilFirstUserAuthentication forFile:[hardLink path]]; - } - - //don't throw any error if the file aready exists, because it could be a rare collision (we only use 16 bit random numbers to keep the file prefix short) - if([_fileManager fileExistsAtPath:[hardLink path]]) - DDLogWarn(@"Not hardlinking file '%@' to '%@': file already exists (maybe a rare collision?)...", cacheFile, hardLink); - else - { - DDLogVerbose(@"Hardlinking cache file '%@' to '%@'...", cacheFile, hardLink); - error = [HelperTools hardLinkOrCopyFile:cacheFile to:[hardLink path]]; - if(error) { - DDLogError(@"Error creating hardlink: %@", error); - @throw [NSException exceptionWithName:@"ERROR_WHILE_HARDLINKING_FILE" reason:[NSString stringWithFormat:@"%@", error] userInfo:@{@"error": error}]; + DDLogVerbose(@"Hardlinking cache file '%@' to '%@'...", cacheFile, hardLink); + error = [HelperTools hardLinkOrCopyFile:cacheFile to:[hardLink path]]; + if(error) + { + DDLogError(@"Error creating hardlink: %@", error); + @throw [NSException exceptionWithName:@"ERROR_WHILE_HARDLINKING_FILE" reason:[NSString stringWithFormat:@"%@", error] userInfo:@{@"error": error}]; + } } } } diff --git a/Monal/Classes/MLXMPPManager.m b/Monal/Classes/MLXMPPManager.m index cfe064a7e9..c316366767 100644 --- a/Monal/Classes/MLXMPPManager.m +++ b/Monal/Classes/MLXMPPManager.m @@ -149,6 +149,8 @@ -(void) defaultSettings [self upgradeBoolUserSettingsIfUnset:@"uploadImagesOriginal" toDefault:NO]; + [self upgradeBoolUserSettingsIfUnset:@"hardlinkFiletransfersIntoDocuments" toDefault:YES]; + // //always show onboarding on simulator for now // #if TARGET_OS_SIMULATOR // [[HelperTools defaultsDB] setBool:NO forKey:@"hasCompletedOnboarding"]; From 2e6265112ff8543aea400966589dcc64766051e7 Mon Sep 17 00:00:00 2001 From: Thilo Molitor Date: Wed, 31 Jul 2024 19:47:23 +0200 Subject: [PATCH 2/2] Add beta changelog back in --- .github/workflows/beta.build-push.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/beta.build-push.yml b/.github/workflows/beta.build-push.yml index 51a4b05472..0a46966e2f 100644 --- a/.github/workflows/beta.build-push.yml +++ b/.github/workflows/beta.build-push.yml @@ -155,6 +155,7 @@ jobs: #run: xcrun altool --upload-app -f ./Monal/build/ipa/Monal.ipa --type ios --asc-provider S8D843U34Y --team-id S8D843U34Y -u "$(cat /Users/ci/apple_connect_upload_mail.txt)" -p "$(cat /Users/ci/apple_connect_upload_secret.txt)" env: PILOT_LOCALIZED_BUILD_INFO: ${{ steps.buildinfo.outputs.buildinfo_ios }} + PILOT_CHANGELOG: ${{ steps.releasenotes.outputs.notes_ios }} run: | fastlane run upload_to_testflight api_key_path:"/Users/ci/appstoreconnect/key.json" team_id:"S8D843U34Y" ipa:"./Monal/build/ipa/Monal.ipa" distribute_external:true groups:"Internal Pre-Beta Testers","Public Beta" reject_build_waiting_for_review:true submit_beta_review:true - name: Notarize catalyst @@ -182,6 +183,7 @@ jobs: #run: xcrun altool --upload-app --file ./Monal/build/app/Monal.pkg --type macos --asc-provider S8D843U34Y -u "$(cat /Users/ci/apple_connect_upload_mail.txt)" -p "$(cat /Users/ci/apple_connect_upload_secret.txt)" --primary-bundle-id org.monal-im.prod.catalyst.monal env: PILOT_LOCALIZED_BUILD_INFO: ${{ steps.buildinfo.outputs.buildinfo_macos }} + PILOT_CHANGELOG: ${{ steps.releasenotes.outputs.notes_macos }} run: | fastlane run upload_to_testflight api_key_path:"/Users/ci/appstoreconnect/key.json" team_id:"S8D843U34Y" pkg:"./Monal/build/app/Monal.pkg" distribute_external:true groups:"Internal Pre-Beta Testers","Public Beta" reject_build_waiting_for_review:true submit_beta_review:true - name: Release