Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2020-03-26 19:52:41 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-03-26 21:57:30 +0300
commitafb1a64ccb81b7ed792f64151986f40f53af8da5 (patch)
treed7dfdb1f1b8d6dda67c91ea813e09fdbb826b335 /source/blender/blenlib/intern/storage_apple.mm
parentd1972e50cbef6e2a40ffc259f10e08493511dc66 (diff)
Fix T60682: adds macOS alias redirection for directories
This adds support for macOS aliases in addition to symlinks. It also adds support for hidden, readonly and system file attributes. Contributed by Ankit (ankitm) with modifications by me. Differential Revision: https://developer.blender.org/D6679
Diffstat (limited to 'source/blender/blenlib/intern/storage_apple.mm')
-rw-r--r--source/blender/blenlib/intern/storage_apple.mm96
1 files changed, 96 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/storage_apple.mm b/source/blender/blenlib/intern/storage_apple.mm
new file mode 100644
index 00000000000..7cb8ca28e24
--- /dev/null
+++ b/source/blender/blenlib/intern/storage_apple.mm
@@ -0,0 +1,96 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bli
+ *
+ * macOS specific implementations for storage.c.
+ */
+
+#import <Foundation/Foundation.h>
+
+#include "BLI_fileops.h"
+#include "BLI_path_util.h"
+
+bool BLI_file_alias_target(char targetpath[FILE_MAXDIR], const char *filepath)
+{
+ @autoreleasepool {
+ NSError *error = nil;
+ NSURL *shortcutURL = [[NSURL alloc] initFileURLWithFileSystemRepresentation:filepath
+ isDirectory:NO
+ relativeToURL:nil];
+ NSURL *targetURL = [NSURL URLByResolvingAliasFileAtURL:shortcutURL
+ options:NSURLBookmarkResolutionWithoutUI
+ error:&error];
+ BOOL isSame = [shortcutURL isEqual:targetURL] and
+ ([[[shortcutURL path] stringByStandardizingPath]
+ isEqualToString:[[targetURL path] stringByStandardizingPath]]);
+
+ if (targetURL == nil) {
+ return false;
+ }
+ else if (isSame) {
+ [targetURL getFileSystemRepresentation:targetpath maxLength:FILE_MAXDIR];
+ return false;
+ }
+ else if (![targetURL getFileSystemRepresentation:targetpath maxLength:FILE_MAXDIR]) {
+ return false;
+ }
+
+ NSNumber *targetIsDirectory = 0;
+ [targetURL getResourceValue:&targetIsDirectory forKey:NSURLIsDirectoryKey error:nil];
+ }
+
+ return true;
+}
+
+eFileAttributes BLI_file_attributes(const char *path)
+{
+ int ret = 0;
+
+ @autoreleasepool {
+ NSURL *fileURL = [[NSURL alloc] initFileURLWithFileSystemRepresentation:path
+ isDirectory:NO
+ relativeToURL:nil];
+ NSArray *resourceKeys =
+ @[ NSURLIsAliasFileKey, NSURLIsHiddenKey, NSURLIsReadableKey, NSURLIsWritableKey ];
+
+ NSDictionary *resourceKeyValues = [fileURL resourceValuesForKeys:resourceKeys error:nil];
+
+ const bool is_alias = [resourceKeyValues[(void)(@"@%"), NSURLIsAliasFileKey] boolValue];
+ const bool is_hidden = [resourceKeyValues[(void)(@"@%"), NSURLIsHiddenKey] boolValue];
+ const bool is_readable = [resourceKeyValues[(void)(@"@%"), NSURLIsReadableKey] boolValue];
+ const bool is_writable = [resourceKeyValues[(void)(@"@%"), NSURLIsWritableKey] boolValue];
+
+ if (is_alias) {
+ ret |= FILE_ATTR_ALIAS;
+ }
+ if (is_hidden) {
+ ret |= FILE_ATTR_HIDDEN;
+ }
+ if (is_readable && !is_writable) {
+ ret |= FILE_ATTR_READONLY;
+ }
+ if (is_readable) {
+ ret |= FILE_ATTR_SYSTEM;
+ }
+ }
+
+ return (eFileAttributes)ret;
+}