Fix T43159: Copying of linked datablocks using relpath leads to invalid paths in...
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 9 Jan 2015 08:52:51 +0000 (09:52 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 9 Jan 2015 08:53:58 +0000 (09:53 +0100)
Propper fix reverting most of rB60e70c0c6014e5, which was only partial specific fix.
This code uses generic `BKE_id_lib_local_paths()` func to handle all possible paths.

Reviewers: sergey, campbellbarton

Differential Revision: https://developer.blender.org/D977

22 files changed:
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/camera.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/group.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/lamp.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/linestyle.c
source/blender/blenkernel/intern/mask.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/speaker.c
source/blender/blenkernel/intern/text.c
source/blender/blenkernel/intern/texture.c
source/blender/blenkernel/intern/world.c

index b066d537fdf386d73bd68a355744c41748aae2e2..f94f1e72638d0b3e8693b5c35a8bb3d41b650b4e 100644 (file)
@@ -215,6 +215,10 @@ bAction *BKE_action_copy(bAction *src)
                }
        }
        
+       if (src->id.lib) {
+               BKE_id_lib_local_paths(G.main, src->id.lib, &dst->id);
+       }
+
        return dst;
 }
 
index f4a5d33854a30ed26224d3722f2539c25d0d5af1..df57db21e3b153734b6ef62a9d5f15f595c8575d 100644 (file)
@@ -222,6 +222,10 @@ bArmature *BKE_armature_copy(bArmature *arm)
        newArm->act_edbone = NULL;
        newArm->sketch = NULL;
 
+       if (arm->id.lib) {
+               BKE_id_lib_local_paths(G.main, arm->id.lib, &newArm->id);
+       }
+
        return newArm;
 }
 
index 7c1915ea2252e4837840cabccb154130ca39e88c..55d347a4fb2dbf99fb6633c8d03cc7c99a124239 100644 (file)
@@ -178,6 +178,10 @@ Brush *BKE_brush_copy(Brush *brush)
                brushn->id.us++;
        }
        
+       if (brush->id.lib) {
+               BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id);
+       }
+
        return brushn;
 }
 
index d0470ba6f6a2596a47366691e45fb3d50a5dd1b5..e424823d8dc585ec7699bf1486f5349236c35fe5 100644 (file)
@@ -78,6 +78,10 @@ Camera *BKE_camera_copy(Camera *cam)
 
        id_lib_extern((ID *)camn->dof_ob);
 
+       if (cam->id.lib) {
+               BKE_id_lib_local_paths(G.main, cam->id.lib, &camn->id);
+       }
+
        return camn;
 }
 
index 937ceffc7650169a974ba324523c8b23b5850539..3abe3c58562e567685632ccafad38b7e88a00a1f 100644 (file)
@@ -237,6 +237,10 @@ Curve *BKE_curve_copy(Curve *cu)
        id_us_plus((ID *)cun->vfonti);
        id_us_plus((ID *)cun->vfontbi);
 
+       if (cu->id.lib) {
+               BKE_id_lib_local_paths(G.main, cu->id.lib, &cun->id);
+       }
+
        return cun;
 }
 
index 6ea6bafaa14758c588f5982adc88ec147946ab07..1f9cf2e11b7f1d984f2acb34bbf3af0f614fccab 100644 (file)
@@ -149,6 +149,10 @@ Group *BKE_group_copy(Group *group)
        groupn = BKE_libblock_copy(&group->id);
        BLI_duplicatelist(&groupn->gobject, &group->gobject);
 
+       if (group->id.lib) {
+               BKE_id_lib_local_paths(G.main, group->id.lib, &groupn->id);
+       }
+
        return groupn;
 }
 
index 3d55340d0528a79b3b76608cfe2c723827f4582f..870c077ff78f7a13442fe741598a1c85492028f2 100644 (file)
@@ -365,11 +365,6 @@ 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;
@@ -389,6 +384,10 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
        if (ima->packedfile)
                nima->packedfile = dupPackedFile(ima->packedfile);
 
+       if (ima->id.lib) {
+               BKE_id_lib_local_paths(bmain, ima->id.lib, &nima->id);
+       }
+
        return nima;
 }
 
index 32e95e7ad92628895b5b702567ad3275e94cd064..560a3c0726b4beae535ae6b334772b3ee875fcf1 100644 (file)
@@ -167,7 +167,11 @@ Key *BKE_key_copy(Key *key)
                kbn = kbn->next;
                kb = kb->next;
        }
-       
+
+       if (key->id.lib) {
+               BKE_id_lib_local_paths(G.main, key->id.lib, &keyn->id);
+       }
+
        return keyn;
 }
 
index e738b16c8cc96f354afdf3caa1a1be1249f8b09e..93b9c22566dd7328e3cbf8b5a188579679d85b38 100644 (file)
@@ -126,6 +126,10 @@ Lamp *BKE_lamp_copy(Lamp *la)
        if (la->preview)
                lan->preview = BKE_previewimg_copy(la->preview);
        
+       if (la->id.lib) {
+               BKE_id_lib_local_paths(G.main, la->id.lib, &lan->id);
+       }
+
        return lan;
 }
 
index 7732d592da663d1df7bb49d824fba9700c602ab5..fa62308ec53c50183460d0d038b05e0034fef4ab 100644 (file)
@@ -284,6 +284,10 @@ Lattice *BKE_lattice_copy(Lattice *lt)
 
        ltn->editlatt = NULL;
 
+       if (lt->id.lib) {
+               BKE_id_lib_local_paths(G.main, lt->id.lib, &ltn->id);
+       }
+
        return ltn;
 }
 
index 5bee93349d89d55ba8fbf0af1a315714a236166d..d244e9d79d20cb7a3f6a852c10e0733f13ae2f6b 100644 (file)
@@ -210,6 +210,10 @@ FreestyleLineStyle *BKE_linestyle_copy(FreestyleLineStyle *linestyle)
        for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next)
                BKE_linestyle_geometry_modifier_copy(new_linestyle, m);
 
+       if (linestyle->id.lib) {
+               BKE_id_lib_local_paths(G.main, linestyle->id.lib, &new_linestyle->id);
+       }
+
        return new_linestyle;
 }
 
index b8c78ce912c7592222f9950b3ce6a3274e1039fa..83ca6cd8d72524ac38b6a0f4cf5347ca3812b529 100644 (file)
@@ -50,6 +50,7 @@
 #include "DNA_sequence_types.h"
 
 #include "BKE_curve.h"
+#include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_mask.h"
@@ -855,6 +856,10 @@ Mask *BKE_mask_copy(Mask *mask)
                mask_new->id.us++;
        }
 
+       if (mask->id.lib) {
+               BKE_id_lib_local_paths(G.main, mask->id.lib, &mask_new->id);
+       }
+
        return mask_new;
 }
 
index 83800a3fb2f4c969afa55fb8c96e5a4b48995679..981064bb22a96fc4c758fcea5ae6db15ce99bee6 100644 (file)
@@ -252,6 +252,10 @@ Material *BKE_material_copy(Material *ma)
 
        BLI_listbase_clear(&man->gpumaterial);
        
+       if (ma->id.lib) {
+               BKE_id_lib_local_paths(G.main, ma->id.lib, &man->id);
+       }
+
        return man;
 }
 
index 4c45269cb0bc0230acb5a1d9e9d769b32e0091d7..34ab2a85593417ce13c2f3af875855f8bfdec5a5 100644 (file)
@@ -238,6 +238,10 @@ MetaBall *BKE_mball_copy(MetaBall *mb)
        mbn->editelems = NULL;
        mbn->lastelem = NULL;
        
+       if (mb->id.lib) {
+               BKE_id_lib_local_paths(G.main, mb->id.lib, &mbn->id);
+       }
+
        return mbn;
 }
 
index 2e80379522c37956669e31d336f51b38119dbcdf..c47d294cfb2f123795617abe2970a87205ae5bdd 100644 (file)
@@ -562,6 +562,10 @@ Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me)
        men->key = BKE_key_copy(me->key);
        if (men->key) men->key->from = (ID *)men;
 
+       if (me->id.lib) {
+               BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);
+       }
+
        return men;
 }
 
index ce86e07ca79731e62dd8ec50a2d7553680f58263..7414a8588ee03177fb40105829c5d5649066ad5b 100644 (file)
@@ -1202,6 +1202,10 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, Main *bmain, bool do_
        /* node tree will generate its own interface type */
        newtree->interface_type = NULL;
        
+       if (ntree->id.lib) {
+               BKE_id_lib_local_paths(bmain, ntree->id.lib, &newtree->id);
+       }
+
        return newtree;
 }
 
index d4a2c327572448481f47aa7a24af7cb7b6ef9782..a9292ac3cf1aef1c3ea4cf06267932bd9a1e0ea0 100644 (file)
@@ -1518,6 +1518,10 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches)
        /* Copy runtime surve data. */
        obn->curve_cache = NULL;
 
+       if (ob->id.lib) {
+               BKE_id_lib_local_paths(bmain, ob->id.lib, &obn->id);
+       }
+
        return obn;
 }
 
index dfc6285146f4f698eb51a052b45018489c433fcd..4868feab0178fc9a7d2d0d3c41993f27b54628ee 100644 (file)
@@ -3701,6 +3701,10 @@ ParticleSettings *BKE_particlesettings_copy(ParticleSettings *part)
 
        BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
        
+       if (part->id.lib) {
+               BKE_id_lib_local_paths(G.main, part->id.lib, &partn->id);
+       }
+
        return partn;
 }
 
index 08daa09cc857070afa76db8e23fddfe66aa98205..b11d0ae03b03e95ed6b90e8373b128a2e73fc8db 100644 (file)
@@ -67,6 +67,10 @@ Speaker *BKE_speaker_copy(Speaker *spk)
        if (spkn->sound)
                spkn->sound->id.us++;
 
+       if (spk->id.lib) {
+               BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
+       }
+
        return spkn;
 }
 
index 86c7f6fcd1a905b14d6c8e412f30a0ad5c4d158b..3a311bfb23be0db8e36d01012282330f67fb24d6 100644 (file)
@@ -455,17 +455,7 @@ Text *BKE_text_copy(Main *bmain, Text *ta)
        
        /* file name can be NULL */
        if (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);
-               }
+               tan->name = BLI_strdup(ta->name);
        }
        else {
                tan->name = NULL;
@@ -499,6 +489,10 @@ Text *BKE_text_copy(Main *bmain, Text *ta)
 
        init_undo_text(tan);
 
+       if (ta->id.lib) {
+               BKE_id_lib_local_paths(bmain, ta->id.lib, &tan->id);
+       }
+
        return tan;
 }
 
index a6536099c5091613a737d2da9f846b8628559de3..dce6584bdfeca44e4edbcc1b5b78b1788fd1536d 100644 (file)
@@ -844,6 +844,10 @@ Tex *BKE_texture_copy(Tex *tex)
                texn->nodetree = ntreeCopyTree(tex->nodetree);
        }
        
+       if (tex->id.lib) {
+               BKE_id_lib_local_paths(G.main, tex->id.lib, &texn->id);
+       }
+
        return texn;
 }
 
index 8113e2bf9efdad5417b6b995d4edb0f9551f56e2..699e0d34161d9dd0eb2a4c63d9b86868d1b2aef6 100644 (file)
@@ -140,7 +140,11 @@ World *BKE_world_copy(World *wrld)
                wrldn->preview = BKE_previewimg_copy(wrld->preview);
 
        BLI_listbase_clear(&wrldn->gpumaterial);
-       
+
+       if (wrld->id.lib) {
+               BKE_id_lib_local_paths(G.main, wrld->id.lib, &wrldn->id);
+       }
+
        return wrldn;
 }