ios/Mobile/DocumentViewController.mm | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
New commits: commit 33d4ad03526da850e3ebc9c1619bcf1d544bada6 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Mon Jun 1 16:54:36 2020 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jun 8 20:46:45 2020 +0200 tdf#133278: Don't overwrite the copy of the document that we are editing When exporting a copy, let core write the copy to a temp subdirectory before invoking UIDocumentPickerViewController to select where to store it permanently. Change-Id: I3d2292414a3c824515ba6d98ad09b296e543cea9 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95295 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tor Lillqvist <t...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95708 Reviewed-by: Andras Timar <andras.ti...@collabora.com> diff --git a/ios/Mobile/DocumentViewController.mm b/ios/Mobile/DocumentViewController.mm index 54932be3f..c94161c02 100644 --- a/ios/Mobile/DocumentViewController.mm +++ b/ios/Mobile/DocumentViewController.mm @@ -16,6 +16,7 @@ #import <objc/runtime.h> #import <poll.h> +#import <sys/stat.h> #import "ios.h" #import "FakeSocket.hpp" @@ -465,8 +466,13 @@ static IMP standardImpOfInputAccessoryView = nil; // First save it in the requested format to a temporary location. First remove any // leftover identically named temporary file. + NSURL *tmpFileDirectory = [[NSFileManager.defaultManager temporaryDirectory] URLByAppendingPathComponent:@"export"]; + if (![NSFileManager.defaultManager createDirectoryAtURL:tmpFileDirectory withIntermediateDirectories:YES attributes:nil error:nil]) { + LOG_ERR("Could not create directory " << [[tmpFileDirectory path] UTF8String]); + return; + } NSString *tmpFileName = [[[self.document->copyFileURL lastPathComponent] stringByDeletingPathExtension] stringByAppendingString:[@"." stringByAppendingString:format]]; - downloadAsTmpURL = [[NSFileManager.defaultManager temporaryDirectory] URLByAppendingPathComponent:tmpFileName]; + downloadAsTmpURL = [tmpFileDirectory URLByAppendingPathComponent:tmpFileName]; std::remove([[downloadAsTmpURL path] UTF8String]); @@ -479,15 +485,15 @@ static IMP standardImpOfInputAccessoryView = nil; struct stat statBuf; if (stat([[downloadAsTmpURL path] UTF8String], &statBuf) == -1) { LOG_ERR("Could apparently not save to '" << [[downloadAsTmpURL path] UTF8String] << "'"); - } else { - UIDocumentPickerViewController *picker = - [[UIDocumentPickerViewController alloc] initWithURL:downloadAsTmpURL - inMode:UIDocumentPickerModeExportToService]; - picker.delegate = self; - [self presentViewController:picker - animated:YES - completion:nil]; + return; } + UIDocumentPickerViewController *picker = + [[UIDocumentPickerViewController alloc] initWithURL:downloadAsTmpURL + inMode:UIDocumentPickerModeExportToService]; + picker.delegate = self; + [self presentViewController:picker + animated:YES + completion:nil]; return; } } @@ -504,10 +510,12 @@ static IMP standardImpOfInputAccessoryView = nil; - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { std::remove([[downloadAsTmpURL path] UTF8String]); + std::remove([[[downloadAsTmpURL URLByDeletingLastPathComponent] path] UTF8String]); } - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { std::remove([[downloadAsTmpURL path] UTF8String]); + std::remove([[[downloadAsTmpURL URLByDeletingLastPathComponent] path] UTF8String]); } - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits