[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55040] trunk/blender/source/blender: patch [#34103] storage_bli_dir_contents.patch
Campbell Barton
ideasman42 at gmail.com
Tue Mar 5 05:24:55 CET 2013
Revision: 55040
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55040
Author: campbellbarton
Date: 2013-03-05 04:24:53 +0000 (Tue, 05 Mar 2013)
Log Message:
-----------
patch [#34103] storage_bli_dir_contents.patch
from Lawrence D'Oliveiro (ldo)
BLI_dir_contents no longer changes current working directory.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/storage.c
trunk/blender/source/blender/editors/interface/interface_icons.c
trunk/blender/source/blender/editors/space_file/filelist.c
Modified: trunk/blender/source/blender/blenlib/intern/storage.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/storage.c 2013-03-05 04:11:55 UTC (rev 55039)
+++ trunk/blender/source/blender/blenlib/intern/storage.c 2013-03-05 04:24:53 UTC (rev 55040)
@@ -221,47 +221,33 @@
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);
+ {
+ const struct dirent *fname;
+ int rellen;
+ char buf[PATH_MAX];
+ BLI_strncpy(buf, relname, sizeof(buf));
+ rellen = strlen(relname);
-#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++;
+ 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 @@
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;
Modified: trunk/blender/source/blender/editors/interface/interface_icons.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_icons.c 2013-03-05 04:11:55 UTC (rev 55039)
+++ trunk/blender/source/blender/editors/interface/interface_icons.c 2013-03-05 04:24:53 UTC (rev 55040)
@@ -704,10 +704,8 @@
{
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 @@
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)) {
Modified: trunk/blender/source/blender/editors/space_file/filelist.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/filelist.c 2013-03-05 04:11:55 UTC (rev 55039)
+++ trunk/blender/source/blender/editors/space_file/filelist.c 2013-03-05 04:24:53 UTC (rev 55040)
@@ -858,18 +858,14 @@
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);
}
More information about the Bf-blender-cvs
mailing list