Blender V4.3
fileops_apple.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#import <Foundation/Foundation.h>
12
13#include "BLI_fileops.h"
14#include "BLI_path_utils.hh"
15
16int BLI_delete_soft(const char *filepath, const char **r_error_message)
17{
18 BLI_assert(!BLI_path_is_rel(filepath));
19
20 @autoreleasepool {
21 NSString *pathString = [NSString stringWithUTF8String:filepath];
22 NSFileManager *fileManager = [NSFileManager defaultManager];
23 NSURL *targetURL = [NSURL fileURLWithPath:pathString];
24
25 BOOL deleteSuccessful = [fileManager trashItemAtURL:targetURL resultingItemURL:nil error:nil];
26
27 if (!deleteSuccessful) {
28 *r_error_message = "The Cocoa API call to delete file or directory failed";
29 }
30
31 return deleteSuccessful ? 0 : -1;
32 }
33}
#define BLI_assert(a)
Definition BLI_assert.h:50
File and directory operations.
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_delete_soft(const char *filepath, const char **r_error_message)
static void error(const char *str)