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:
authorCampbell Barton <ideasman42@gmail.com>2013-03-05 08:24:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-03-05 08:24:53 +0400
commit65d6cecd68a22f140d2acc0d8dd5abf68723ed2e (patch)
tree9ebb0aca923009ca09bd05f6f57297860a4a921d /source/blender
parent2fc10e330335882390dfe7c70bcc78e975642b19 (diff)
patch [#34103] storage_bli_dir_contents.patch
from Lawrence D'Oliveiro (ldo) BLI_dir_contents no longer changes current working directory.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/intern/storage.c66
-rw-r--r--source/blender/editors/interface/interface_icons.c7
-rw-r--r--source/blender/editors/space_file/filelist.c4
3 files changed, 27 insertions, 50 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 6bc8980c646..9263c250944 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -221,47 +221,33 @@ static void bli_builddir(const char *dirname, const char *relname,
struct BuildDirCtx *dir_ctx)
{
struct ListBase dirbase = {NULL, NULL};
- int rellen, newnum = 0;
- char buf[256];
+ int newnum = 0;
DIR *dir;
- BLI_strncpy(buf, relname, sizeof(buf));
- rellen = strlen(relname);
+ if ((dir = opendir(dirname)) != NULL) {
- if (rellen) {
- buf[rellen] = '/';
- rellen++;
- }
- /* FIXME: any reason why we can't opendir dirname directly, instead of making it
- * the current directory first? That would simplify calls to this routine (currently
- * having to save/restore the current directory) a lot. */
-#ifndef WIN32
- if (chdir(dirname) == -1) {
- perror(dirname);
- return;
- }
-#else
- UTF16_ENCODE(dirname);
- if (!SetCurrentDirectoryW(dirname_16)) {
- perror(dirname);
- free(dirname_16);
- return;
- }
- UTF16_UN_ENCODE(dirname);
-
-#endif
- if ((dir = opendir(".")) != NULL) {
- const struct dirent *fname;
- while ((fname = readdir(dir)) != NULL) {
- struct dirlink * const dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
- if (dlink != NULL) {
- BLI_strncpy(buf + rellen, fname->d_name, sizeof(buf) - rellen);
- dlink->name = BLI_strdup(buf);
- BLI_addhead(&dirbase, dlink);
- newnum++;
+ {
+ const struct dirent *fname;
+ int rellen;
+ char buf[PATH_MAX];
+ BLI_strncpy(buf, relname, sizeof(buf));
+ rellen = strlen(relname);
+
+ if (rellen) {
+ buf[rellen] = '/';
+ rellen++;
+ }
+ while ((fname = readdir(dir)) != NULL) {
+ struct dirlink * const dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
+ if (dlink != NULL) {
+ BLI_strncpy(buf + rellen, fname->d_name, sizeof(buf) - rellen);
+ dlink->name = BLI_strdup(buf);
+ BLI_addhead(&dirbase, dlink);
+ newnum++;
+ }
}
}
-
+
if (newnum) {
if (dir_ctx->files) {
@@ -282,24 +268,26 @@ static void bli_builddir(const char *dirname, const char *relname,
struct dirlink * dlink = (struct dirlink *) dirbase.first;
struct direntry *file = &dir_ctx->files[dir_ctx->nrfiles];
while (dlink) {
+ char fullname[PATH_MAX];
memset(file, 0, sizeof(struct direntry));
file->relname = dlink->name;
file->path = BLI_strdupcat(dirname, dlink->name);
+ BLI_join_dirfile(fullname, sizeof fullname, dirname, dlink->name);
// use 64 bit file size, only needed for WIN32 and WIN64.
// Excluding other than current MSVC compiler until able to test
#ifdef WIN32
{
- wchar_t *name_16 = alloc_utf16_from_8(dlink->name, 0);
+ wchar_t *name_16 = alloc_utf16_from_8(fullname, 0);
#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER >= 1500)
_wstat64(name_16, &entry->s);
#elif defined(__MINGW32__)
- _stati64(dlink->name, &entry->s);
+ _stati64(fullname, &entry->s);
#endif
free(name_16);
}
#else
- stat(dlink->name, &file->s);
+ stat(fullname, &file->s);
#endif
file->type = file->s.st_mode;
file->flags = 0;
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 0defc74a67b..09686d7b416 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -704,10 +704,8 @@ static void init_iconfile_list(struct ListBase *list)
{
IconFile *ifile;
struct direntry *dir;
- int restoredir = 1; /* restore to current directory */
int totfile, i, index = 1;
const char *icondir;
- char olddir[FILE_MAX];
list->first = list->last = NULL;
icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
@@ -715,12 +713,7 @@ static void init_iconfile_list(struct ListBase *list)
if (icondir == NULL)
return;
- /* since BLI_dir_contents changes the current working directory, restore it
- * back to old value afterwards */
- if (!BLI_current_working_dir(olddir, sizeof(olddir)))
- restoredir = 0;
totfile = BLI_dir_contents(icondir, &dir);
- if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */
for (i = 0; i < totfile; i++) {
if ((dir[i].type & S_IFREG)) {
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 5be780ff0b4..d3366383e60 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -858,18 +858,14 @@ static void filelist_setfiletypes(struct FileList *filelist)
static void filelist_read_dir(struct FileList *filelist)
{
- char wdir[FILE_MAX] = "";
if (!filelist) return;
filelist->fidx = NULL;
filelist->filelist = NULL;
- BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */
-
BLI_cleanup_dir(G.main->name, filelist->dir);
filelist->numfiles = BLI_dir_contents(filelist->dir, &(filelist->filelist));
- if (!chdir(wdir)) {} /* fix warning about not checking return value */
filelist_setfiletypes(filelist);
filelist_filter(filelist);
}