Files
test/source/blender/blenlib/intern/fileops_apple.mm
Jonas Holzman fe93de1a91 Obj-C Refactor: Port BLI_delete_soft from objc_* runtime calls to proper Obj-C
Port the macOS version of the `BLI_delete_soft` function from raw
runtime `objc_*` calls function to proper Objective-C for increased
readability and long-term maintainability. This new function is placed
in a new `intern/fileops_apple.mm` file, analogous to the existing
`intern/storage_apple.mm` file.

Pull Request: https://projects.blender.org/blender/blender/pulls/126766
2024-09-03 12:08:20 +02:00

34 lines
870 B
Plaintext

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bli
*
* macOS specific implementations for fileops{_c}.cc.
*/
#import <Foundation/Foundation.h>
#include "BLI_fileops.h"
#include "BLI_path_util.h"
int BLI_delete_soft(const char *filepath, const char **r_error_message)
{
BLI_assert(!BLI_path_is_rel(filepath));
@autoreleasepool {
NSString *pathString = [NSString stringWithUTF8String:filepath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *targetURL = [NSURL fileURLWithPath:pathString];
BOOL deleteSuccessful = [fileManager trashItemAtURL:targetURL resultingItemURL:nil error:nil];
if (!deleteSuccessful) {
*r_error_message = "The Cocoa API call to delete file or directory failed";
}
return deleteSuccessful ? 0 : -1;
}
}