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:
authorAnkit Meel <ankitjmeel@gmail.com>2020-10-09 12:09:26 +0300
committerAnkit Meel <ankitjmeel@gmail.com>2020-10-09 20:16:39 +0300
commit32d4623f4467df230c08d24916759ac4996dfb52 (patch)
treeb3ef4eb73f3470f49a4256d1656bc40cea76601d /source/blender/blenlib/intern
parent62f5232f37b9755bfa07a174a47017cd1609fb5a (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')
-rw-r--r--source/blender/blenlib/intern/storage.c16
-rw-r--r--source/blender/blenlib/intern/storage_apple.mm36
2 files changed, 27 insertions, 25 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index a841068bfdb..628bdc1a31f 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -288,11 +288,11 @@ eFileAttributes BLI_file_attributes(const char *path)
/* Return alias/shortcut file target. Apple version is defined in storage_apple.mm */
#ifndef __APPLE__
-bool BLI_file_alias_target(
- /* This parameter can only be const on non-windows platforms.
- * NOLINTNEXTLINE: readability-non-const-parameter. */
- char target[FILE_MAXDIR],
- const char *filepath)
+bool BLI_file_alias_target(const char *filepath,
+ /* This parameter can only be `const` on Linux since
+ * redirections are not supported there.
+ * NOLINTNEXTLINE: readability-non-const-parameter. */
+ char r_targetpath[FILE_MAXDIR])
{
# ifdef WIN32
if (!BLI_path_extension_check(filepath, ".lnk")) {
@@ -318,7 +318,7 @@ bool BLI_file_alias_target(
wchar_t target_utf16[FILE_MAXDIR] = {0};
hr = Shortcut->lpVtbl->GetPath(Shortcut, target_utf16, FILE_MAXDIR, NULL, 0);
if (SUCCEEDED(hr)) {
- success = (conv_utf_16_to_8(target_utf16, target, FILE_MAXDIR) == 0);
+ success = (conv_utf_16_to_8(target_utf16, r_targetpath, FILE_MAXDIR) == 0);
}
}
PersistFile->lpVtbl->Release(PersistFile);
@@ -328,9 +328,9 @@ bool BLI_file_alias_target(
Shortcut->lpVtbl->Release(Shortcut);
}
- return (success && target[0]);
+ return (success && r_targetpath[0]);
# else
- UNUSED_VARS(target, filepath);
+ UNUSED_VARS(r_targetpath, filepath);
/* File-based redirection not supported. */
return false;
# endif
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];