eina_file: check copied using copied

Summary:
From (1) "the following commit" message, the changed condition in this patch
should check if the virtualized file is copied or not.

In eina_file_virtualize
head_padded = 16 * ((sizeof(Eina_File) + slen + 15) / 16);
file->global_map = ((char *)file) + head_padded;

In eina_file_dup
file->global_map != (void*)(file->filename + strlen(file->filename) + 1)

Because of this discord condition makes eina_file_dup copies always.

(1) This is "the following commit":
commit 4766316935
Author: Cedric Bail <cedric@osg.samsung.com>
Date:   Wed Mar 8 10:13:36 2017 -0800

    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

Reviewers: zmike, Hermet

Reviewed By: zmike

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D6857
This commit is contained in:
Shinwoo Kim 2018-08-17 12:42:18 -04:00 committed by Mike Blumenkrantz
parent ae894a0509
commit cbe9b6f770
1 changed files with 7 additions and 9 deletions

View File

@ -474,18 +474,16 @@ 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->virtual && !file->copied)
{
// 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;
Eina_File *r;
r = eina_file_virtualize(file->filename, file->global_map, file->length, EINA_TRUE);
eina_lock_release(&file->lock);
r = eina_file_virtualize(file->filename, file->global_map, file->length, EINA_TRUE);
eina_lock_release(&file->lock);
return r;
}
return r;
}
file->refcount++;
eina_lock_release(&file->lock);