[sword-devel] Confusing semantics for FileMgr::existsFile() and FileMgr::existsDir()
Troy A. Griffitts
scribe at crosswire.org
Sun Oct 23 01:50:25 MST 2016
Thanks for the suggestion Jaak. While I understand your concern,
testing for readability on OSs which support such is ancillary to the
purpose of the call. The purpose of the call is the see if a file or
directory exists. When the engine makes these checks, it typically is
about to do something with the file or directory if it does exists and
thus we added an extra check for readability, i.e., if it does exists
and isn't readable to us, it might as well not exist, for our purposes.
99.99% of the checks with either result in the file existing or not
existing. It should be a very rare cases where a SWORD file or folder
is found, but we don't have read access to it. I feel that changing the
name to isReadable is counter intuitive to the purpose of the call.
But I do appreciate your suggestion,
On 10/22/2016 01:21 AM, Jaak Ristioja wrote:
> I instead suggest having a single function called isReadable(path) or
> similar. Because when reading code like
> if (exists(path))
> one will easily (if not always) miss that comment. If you keep calling
> these existsFile() and existsDir() one will most likely assume
> isFile()/isDir() semantics, while in reality these both instead have
> isReadable() semantics.
> On 22.10.2016 06:50, Troy A. Griffitts wrote:
>> Thanks for pointing this out Jaak. I've updated the comments to reflect
>> that not only are file and dir checked for existence, but are also
>> checked for readability.
>> On 10/21/2016 12:56 PM, Jaak Ristioja wrote:
>>> In reality, the FileMgr::existsFile() and FileMgr::existsDir() static
>>> methods not only check whether a file exists (or is visible to the
>>> calling process), but also whether the given file is readable, because
>>> internally, it uses the ::access system call with mode set to 04 which
>>> is R_OK. Whereas it would suffice to use F_OK to check for existance.
>>> What should the correct semantics and function names be?
>>> PS: Semantically, these two functions seem to duplicate one another,
>>> except for memory requirements.
>>> sword-devel mailing list: sword-devel at crosswire.org
>>> Instructions to unsubscribe/change your settings at above page
>> sword-devel mailing list: sword-devel at crosswire.org
>> Instructions to unsubscribe/change your settings at above page
> sword-devel mailing list: sword-devel at crosswire.org
> Instructions to unsubscribe/change your settings at above page
More information about the sword-devel