diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-01-08 16:38:48 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-01-08 16:38:48 +0300 |
commit | 60e70c0c6014e51954473e075a7679ad24648acd (patch) | |
tree | 55454702573809436f98d5e6dbee2d13325146de /source/blender/blenkernel/intern | |
parent | 72ca9526411797220ea3b14d63d49c72a15ea2c1 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 15 |
3 files changed, 18 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index bb68f963c2e..3d55340d052 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 32fc10d3ccc..752c2961f28 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 77629715edb..86c7f6fcd1a 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; |