Commit: 60e70c0c6014e51954473e075a7679ad24648acd
Author: Bastien Montagne
Date:   Thu Jan 8 14:38:48 2015 +0100
Branches: master
https://developer.blender.org/rB60e70c0c6014e51954473e075a7679ad24648acd

Fix T43159: Copying of linked datablocks using relpath leads to invalid paths 
in new copies.

Simply have to rebase onto main filepath when copying, if source datablock is 
lib and path is relative.

Afaict, only affected Image and Text datablocks. MovieClip would also be a 
candidate, but has
no copy implemented currently.

===================================================================

M       source/blender/blenkernel/BKE_text.h
M       source/blender/blenkernel/intern/image.c
M       source/blender/blenkernel/intern/library.c
M       source/blender/blenkernel/intern/text.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_text.h 
b/source/blender/blenkernel/BKE_text.h
index 1e79eaa..96e88f8 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -51,7 +51,7 @@ int                           BKE_text_reload         (struct 
Text *text);
 struct Text    *BKE_text_load_ex(struct Main *bmain, const char *file, const 
char *relpath,
                                  const bool is_internal);
 struct Text    *BKE_text_load  (struct Main *bmain, const char *file, const 
char *relpath);
-struct Text    *BKE_text_copy          (struct Text *ta);
+struct Text    *BKE_text_copy          (struct Main *bmain, struct Text *ta);
 void                   BKE_text_unlink         (struct Main *bmain, struct 
Text *text);
 void                   BKE_text_clear      (struct Text *text);
 void                   BKE_text_write      (struct Text *text, const char 
*str);
diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index bb68f96..3d55340 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -365,6 +365,11 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
        Image *nima = image_alloc(bmain, ima->id.name + 2, ima->source, 
ima->type);
 
        BLI_strncpy(nima->name, ima->name, sizeof(ima->name));
+       if (ima->id.lib && BLI_path_is_rel(ima->name)) {
+               /* If path is relative, and source is a lib, path is relative 
to lib file, not main one! */
+               BLI_path_abs(nima->name, ima->id.lib->filepath);
+               BLI_path_rel(nima->name, bmain->name);
+       }
 
        nima->flag = ima->flag;
        nima->tpageflag = ima->tpageflag;
diff --git a/source/blender/blenkernel/intern/library.c 
b/source/blender/blenkernel/intern/library.c
index 32fc10d..752c296 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -351,7 +351,7 @@ bool id_copy(ID *id, ID **newid, bool test)
                case ID_VF:
                        return false;  /* not implemented */
                case ID_TXT:
-                       if (!test) *newid = (ID *)BKE_text_copy((Text *)id);
+                       if (!test) *newid = (ID *)BKE_text_copy(G.main, (Text 
*)id);
                        return true;
                case ID_SCRIPT:
                        return false;  /* deprecated */
diff --git a/source/blender/blenkernel/intern/text.c 
b/source/blender/blenkernel/intern/text.c
index 7762971..86c7f6f 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -446,7 +446,7 @@ Text *BKE_text_load(Main *bmain, const char *file, const 
char *relpath)
        return BKE_text_load_ex(bmain, file, relpath, false);
 }
 
-Text *BKE_text_copy(Text *ta)
+Text *BKE_text_copy(Main *bmain, Text *ta)
 {
        Text *tan;
        TextLine *line, *tmp;
@@ -455,8 +455,17 @@ Text *BKE_text_copy(Text *ta)
        
        /* file name can be NULL */
        if (ta->name) {
-               tan->name = MEM_mallocN(strlen(ta->name) + 1, "text_name");
-               strcpy(tan->name, ta->name);
+               if (ta->id.lib && BLI_path_is_rel(ta->name)) {
+                       char tname[FILE_MAXFILE];
+                       /* If path is relative, and source is a lib, path is 
relative to lib file, not main one! */
+                       BLI_strncpy(tname, ta->name, sizeof(tname));
+                       BLI_path_abs(tname, ta->id.lib->filepath);
+                       BLI_path_rel(tname, bmain->name);
+                       tan->name = BLI_strdup(tname);
+               }
+               else {
+                       tan->name = BLI_strdup(ta->name);
+               }
        }
        else {
                tan->name = NULL;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to