Fix up deleteAttachments method since making attachmentFolder

dispatchOnce

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 1d71ca5e50
commit 605db6b788

@ -294,10 +294,28 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)deleteAttachments + (void)deleteAttachments
{ {
NSError *error; NSError *error;
[[NSFileManager defaultManager] removeItemAtPath:[self attachmentsFolder] error:&error];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *fileURL = [NSURL fileURLWithPath:self.attachmentsFolder];
NSArray<NSURL *> *contents =
[fileManager contentsOfDirectoryAtURL:fileURL includingPropertiesForKeys:nil options:0 error:&error];
if (error) { if (error) {
DDLogError(@"Failed to delete attachment folder with error: %@", error.debugDescription); OWSFail(@"failed to get contents of attachments folder: %@ with error: %@", self.attachmentsFolder, error);
return;
} }
for (NSURL *url in contents) {
NSError *deletionError;
[fileManager removeItemAtURL:url error:&deletionError];
if (deletionError) {
OWSFail(@"failed to remove item at path: %@ with error: %@", filePath, deletionError);
// continue to try to delete remaining items.
}
}
return;
} }
- (CGSize)calculateImageSize - (CGSize)calculateImageSize

@ -1,5 +1,6 @@
// Created by Michael Kirk on 9/23/16. //
// Copyright © 2016 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "NSDate+millisecondTimeStamp.h" #import "NSDate+millisecondTimeStamp.h"
#import "OWSDisappearingMessagesFinder.h" #import "OWSDisappearingMessagesFinder.h"

@ -76,6 +76,9 @@
- (void)testFilesWithoutInteractionsAreDeleted - (void)testFilesWithoutInteractionsAreDeleted
{ {
// sanity check
XCTAssertEqual(0, [TSAttachmentStream numberOfItemsInAttachmentsFolder]);
NSError *error; NSError *error;
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil]; TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
[attachmentStream writeData:[NSData new] error:&error]; [attachmentStream writeData:[NSData new] error:&error];
@ -129,7 +132,6 @@
[attachmentStream writeData:[NSData new] error:&error]; [attachmentStream writeData:[NSData new] error:&error];
// Intentionally not saved, because we want a lingering file. // Intentionally not saved, because we want a lingering file.
NSString *orphanedFilePath = [attachmentStream filePath]; NSString *orphanedFilePath = [attachmentStream filePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:orphanedFilePath]; BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:orphanedFilePath];
XCTAssert(fileExists); XCTAssert(fileExists);

Loading…
Cancel
Save