[Bf-committers] Fix bug: 1013

Ton Roosendaal bf-committers@blender.org
Mon, 5 Apr 2004 13:21:04 +0200


Hi,

The first half of the patch (copying G.lib) I can see why.
But the 2nd part I fail to understand. The file is supposed to be  
closed in the function blo_freefiledata()... which happens in the  
read_libraries().

And why change (file == -1) to (file < 0)?

Anyhoo. After some researching in this old code, I found out the file  
descriptors for library files are not immediately closed (but they  
*are* closed). This only causes errors when accidentally browsing the  
'current' file, and try to save over with CTRL+W. To keep it cleaner,  
I've made a patch in filesel.c to prevent selecting (or browsing) the  
current file.

filesel.c line 508:

				if(sfile->type==FILE_LOADLIB) {
					char name[FILE_MAXDIR+FILE_MAXFILE];
					strcpy(name, sfile->dir);
					strcat(name, file->relname);
					/* prevent current file being used as acceptable dir */
					if (BLI_streq(G.main->name, name)==0) {
						file->type &= ~S_IFMT;
						file->type |= S_IFDIR;
					}
				}


BTW:
For discussions on code changes like this, I find 'diff' patches very  
hard to read, and I won't apply patches in this very sensitive code  
without a very careful check. :)

-Ton-


On Sunday, Apr 4, 2004, at 23:21 Europe/Amsterdam, Kenneth Styrberg  
wrote:

> Here's a fix for bug 1013. This prevents appending from current/active  
> file (SHIFT+f1), and fixes the breakage on version backups (CTRL+w).  
> Tested on W98SE.
>
> //styken
>
>
> ===================================================================
> RCS file: /cvsroot/bf-blender/blender/source/blender/src/filesel.c,v
> retrieving revision 1.32
> diff -u -r1.32 filesel.c
> --- filesel.c 2 Mar 2004 16:49:50 -0000 1.32
> +++ filesel.c 4 Apr 2004 21:20:01 -0000
> @@ -2236,6 +2236,7 @@
>   } else if (group[0]==0) {
>    error("Nothing indicated");
>   } else if (BLI_streq(G.main->name, dir)) {
> +  strcpy(G.lib, dir);
>    error("Cannot use current file as library");
>   } else {
>    Object *ob;
>
> ===================================================================
> RCS file:  
> /cvsroot/bf-blender/blender/source/blender/blenloader/intern/ 
> readfile.c,v
> retrieving revision 1.44
> diff -u -r1.44 readfile.c
> --- readfile.c 20 Mar 2004 22:55:38 -0000 1.44
> +++ readfile.c 4 Apr 2004 21:15:13 -0000
> @@ -785,7 +785,7 @@
>  {
>   int file= open(name, O_BINARY|O_RDONLY);
>
> - if (file == -1) {
> + if (file < 0) {
>    return NULL;
>   } else {
>    FileData *fd = filedata_new();
> @@ -804,7 +804,7 @@
>     blo_freefiledata(fd);
>     fd= NULL;
>    }
> -
> +  close(file);
>    return fd;
>   }
>  }
>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers@blender.org
> http://www.blender.org/mailman/listinfo/bf-committers
>
>
------------------------------------------------------------------------ 
--
Ton Roosendaal  Blender Foundation ton@blender.org  
http://www.blender.org