diff options
author | Ankit Meel <ankitjmeel@gmail.com> | 2020-10-09 12:09:26 +0300 |
---|---|---|
committer | Ankit Meel <ankitjmeel@gmail.com> | 2020-10-09 20:16:39 +0300 |
commit | 32d4623f4467df230c08d24916759ac4996dfb52 (patch) | |
tree | b3ef4eb73f3470f49a4256d1656bc40cea76601d /source/blender/blenlib/intern/storage_apple.mm | |
parent | 62f5232f37b9755bfa07a174a47017cd1609fb5a (diff) |
Cleanup: alias: use const, remove unused variable.
`targetIsDirectory` slipped through the code review of
{D6679}/{rBafb1a64ccb81}.
`BLI_is_dir` exists to check for directory status of a file.
Remove some `else-after-return`s.
Use `r_` prefix for return value arguments, and move it to the end
in the list of arguments.
Diffstat (limited to 'source/blender/blenlib/intern/storage_apple.mm')
-rw-r--r-- | source/blender/blenlib/intern/storage_apple.mm | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/source/blender/blenlib/intern/storage_apple.mm b/source/blender/blenlib/intern/storage_apple.mm index 08d2cfdf4a4..16a2fd338fa 100644 --- a/source/blender/blenlib/intern/storage_apple.mm +++ b/source/blender/blenlib/intern/storage_apple.mm @@ -28,7 +28,11 @@ #include "BLI_fileops.h" #include "BLI_path_util.h" -bool BLI_file_alias_target(char targetpath[FILE_MAXDIR], const char *filepath) +/** + * \param r_targetpath Buffer for the target path an alias points to. + * \return Whether the file at the input path is an alias. + */ +bool BLI_file_alias_target(const char *filepath, char r_targetpath[FILE_MAXDIR]) { /* clang-format off */ @autoreleasepool { @@ -37,26 +41,24 @@ bool BLI_file_alias_target(char targetpath[FILE_MAXDIR], const char *filepath) 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]]); + const NSURL *targetURL = [NSURL URLByResolvingAliasFileAtURL:shortcutURL + options:NSURLBookmarkResolutionWithoutUI + error:&error]; + const 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]; + if (isSame) { + [targetURL getFileSystemRepresentation:r_targetpath maxLength:FILE_MAXDIR]; return false; } - else if (![targetURL getFileSystemRepresentation:targetpath maxLength:FILE_MAXDIR]) { + /* Note that the if-condition may also change the value of `r_targetpath`. */ + if (![targetURL getFileSystemRepresentation:r_targetpath maxLength:FILE_MAXDIR]) { return false; } - - NSNumber *targetIsDirectory = 0; - [targetURL getResourceValue:&targetIsDirectory forKey:NSURLIsDirectoryKey error:nil]; } return true; @@ -69,13 +71,13 @@ eFileAttributes BLI_file_attributes(const char *path) /* clang-format off */ @autoreleasepool { /* clang-format on */ - NSURL *fileURL = [[NSURL alloc] initFileURLWithFileSystemRepresentation:path - isDirectory:NO - relativeToURL:nil]; + const NSURL *fileURL = [[NSURL alloc] initFileURLWithFileSystemRepresentation:path + isDirectory:NO + relativeToURL:nil]; NSArray *resourceKeys = @[ NSURLIsAliasFileKey, NSURLIsHiddenKey, NSURLIsReadableKey, NSURLIsWritableKey ]; - NSDictionary *resourceKeyValues = [fileURL resourceValuesForKeys:resourceKeys error:nil]; + const NSDictionary *resourceKeyValues = [fileURL resourceValuesForKeys:resourceKeys error:nil]; const bool is_alias = [resourceKeyValues[(void)(@"@%"), NSURLIsAliasFileKey] boolValue]; const bool is_hidden = [resourceKeyValues[(void)(@"@%"), NSURLIsHiddenKey] boolValue]; |