From afb1a64ccb81b7ed792f64151986f40f53af8da5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 26 Mar 2020 17:52:41 +0100 Subject: 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 --- source/blender/editors/space_file/file_ops.c | 4 +++- source/blender/editors/space_file/filelist.c | 31 ++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'source/blender/editors/space_file') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index a34fcba99be..5258892d55d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1634,7 +1634,9 @@ static int file_exec(bContext *C, wmOperator *exec_op) BLI_path_append(sfile->params->dir, sizeof(sfile->params->dir) - 1, file->relpath); BLI_add_slash(sfile->params->dir); } - + if (file->redirection_path) { + STRNCPY(sfile->params->dir, file->redirection_path); + } ED_file_change_dir(C); } /* opening file - sends events now, so things get handled on windowqueue level */ diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index caab1ac74d0..dec38501d38 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -210,12 +210,13 @@ typedef struct FileListInternEntry { int blentype; char *relpath; + /** Optional argument for shortcuts, aliases etc. */ + char *redirection_path; /** not strictly needed, but used during sorting, avoids to have to recompute it there... */ char *name; /** Defined in BLI_fileops.h */ eFileAttributes attributes; - BLI_stat_t st; } FileListInternEntry; @@ -961,12 +962,12 @@ ImBuf *filelist_getimage(struct FileList *filelist, const int index) return file->image; } -static ImBuf *filelist_geticon_image_ex(const unsigned int typeflag, const char *relpath) +static ImBuf *filelist_geticon_image_ex(FileDirEntry *file) { ImBuf *ibuf = NULL; - if (typeflag & FILE_TYPE_DIR) { - if (FILENAME_IS_PARENT(relpath)) { + if (file->typeflag & FILE_TYPE_DIR) { + if (FILENAME_IS_PARENT(file->relpath)) { ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT]; } else { @@ -983,8 +984,7 @@ static ImBuf *filelist_geticon_image_ex(const unsigned int typeflag, const char ImBuf *filelist_geticon_image(struct FileList *filelist, const int index) { FileDirEntry *file = filelist_geticon_get_file(filelist, index); - - return filelist_geticon_image_ex(file->typeflag, file->relpath); + return filelist_geticon_image_ex(file); } static int filelist_geticon_ex(FileDirEntry *file, @@ -1170,6 +1170,9 @@ static void filelist_entry_clear(FileDirEntry *entry) if (entry->relpath) { MEM_freeN(entry->relpath); } + if (entry->redirection_path) { + MEM_freeN(entry->redirection_path); + } if (entry->image) { IMB_freeImBuf(entry->image); } @@ -1239,6 +1242,9 @@ static void filelist_intern_entry_free(FileListInternEntry *entry) if (entry->relpath) { MEM_freeN(entry->relpath); } + if (entry->redirection_path) { + MEM_freeN(entry->redirection_path); + } if (entry->name) { MEM_freeN(entry->name); } @@ -1690,6 +1696,9 @@ static FileDirEntry *filelist_file_create_entry(FileList *filelist, const int in ret->blentype = entry->blentype; ret->typeflag = entry->typeflag; ret->attributes = entry->attributes; + if (entry->redirection_path) { + ret->redirection_path = BLI_strdup(entry->redirection_path); + } BLI_addtail(&cache->cached_entries, ret); return ret; } @@ -2523,6 +2532,16 @@ static int filelist_readjob_list_dir(const char *root, /* Set file attributes. */ entry->attributes = BLI_file_attributes(path); + if (entry->attributes & FILE_ATTR_ALIAS) { + entry->redirection_path = MEM_callocN(FILE_MAXDIR, __func__); + if (BLI_file_alias_target(entry->redirection_path, path)) { + if (BLI_is_dir(entry->redirection_path)) { + entry->typeflag = FILE_TYPE_DIR; + } + else + entry->typeflag = ED_path_extension_type(entry->redirection_path); + } + } #ifndef WIN32 /* Set linux-style dot files hidden too. */ -- cgit v1.2.3