eina: force copy of not copied virtualized file while doing an eina_file_dup.

The other way around is pretty much impossible as you don't know who does
an eina_file_dup and for how long they keep there reference.

T5234
This commit is contained in:
Cedric Bail 2017-03-08 10:13:36 -08:00
parent 8ed9aec49b
commit 4766316935
1 changed files with 13 additions and 0 deletions

View File

@ -477,6 +477,19 @@ eina_file_dup(const Eina_File *f)
{
EINA_FILE_MAGIC_CHECK(f, NULL);
eina_lock_take(&file->lock);
if (file->virtual)
{
// For ease of use and safety of the API, if you dup a virtualized file, we prefer to make a copy
if (file->global_map != (void*)(file->filename + strlen(file->filename) + 1))
{
Eina_File *r;
r = eina_file_virtualize(file->filename, file->global_map, file->length, EINA_TRUE);
eina_lock_release(&file->lock);
return r;
}
}
file->refcount++;
eina_lock_release(&file->lock);
}