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 | |
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')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 2 | ||||
-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 |
4 files changed, 19 insertions, 5 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 1e79eaa8431..96e88f80464 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 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; |