Results 1 to 2 of 2

Thread: Issues in 'CL_VirtualFileSystem::has_directory' and 'CL_VirtualFileSystem::has_file'

  1. #1

    Post Issues in 'CL_VirtualFileSystem::has_directory' and 'CL_VirtualFileSystem::has_file'

    Dear All,


    I noticed that both methods will fail if your input contains path components.

    For example, if you have a virtual file system, regardless it is a actual directory on the disk or a zipped archive file, that has the following structure:

    /-
    .|-A
    ....|-Aa
    ........|-001.txt


    Then, presumably, you should be able to use the following statement to test whether the file '001.txt' is exist:

    "vfs_instance.has_file("/A/Aa/001.txt");"

    Unfortunately, this statement will return "false" even there is indeed a file named "001.txt" exist in this virtual file system.


    The reason of this unexpected behaviour, in my opinion, is that in the "has_file" implementation, the input parameter is compared with each entries in the "CL_VirtualDirectoryListing" directly. The file names retrieved from the entries in the "CL_VirtualDirectoryListing", by using "list.get_filename()" method, do not have the path information and only has the actual file name part (i.e. "001.txt" rather than "/A/Aa/001.txt"). In this case, if we compare this (only) file name part against the full path to this file (the input parameter), it will fail.


    My recommend change related to this issue is as follows:


    Index: Core/IOData/virtual_file_system.cpp
    ================================================== =================
    --- Core/IOData/virtual_file_system.cpp (revision 7479)
    +++ Core/IOData/virtual_file_system.cpp (working copy)
    @@ -272,9 +272,10 @@
    bool CL_VirtualFileSystem::has_directory(const CL_String &directory)
    {
    CL_VirtualDirectoryListing list = get_directory_listing(CL_PathHelp::get_basepath(di rectory, CL_PathHelp:ath_type_virtual));
    + CL_String dir_name = CL_PathHelp::get_filename(CL_PathHelp::remove_trai ling_slash(directory));
    while (list.next())
    {
    - if (directory == list.get_filename() && list.is_directory())
    + if (dir_name == list.get_filename() && list.is_directory())
    return true;
    }

    @@ -284,9 +285,10 @@
    bool CL_VirtualFileSystem::has_file(const CL_String &filename)
    {
    CL_VirtualDirectoryListing list = get_directory_listing(CL_PathHelp::get_basepath(fi lename, CL_PathHelp:ath_type_virtual));
    + CL_String fil_name = CL_PathHelp::get_filename(filename);
    while (list.next())
    {
    - if (filename == list.get_filename() && !list.is_directory())
    + if (fil_name == list.get_filename() && !list.is_directory())
    return true;
    }



    The patch file is attached for your convenience.




    Best regards,


    Chris
    Attached Files Attached Files

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,774

    Default

    Patch applied to ClanLib 2.3 SVN and ClanLib 2.4 SVN. Many thanks

Similar Threads

  1. Four Suggestions and Issues
    By Junior in forum Tanked
    Replies: 13
    Last Post: 04-04-2012, 11:37 AM
  2. Issues with a Pre 2?
    By Coalition in forum Tanked
    Replies: 2
    Last Post: 12-02-2011, 02:39 PM
  3. Possible bug in CL_VirtualFileSystem::has_file
    By leiradel in forum ClanLib: Help
    Replies: 0
    Last Post: 10-31-2011, 03:21 AM
  4. CL_GUIComponent Issues
    By Fr3DBr in forum ClanLib: Help
    Replies: 2
    Last Post: 08-31-2009, 05:09 PM
  5. Issues
    By Dorian1 in forum RTsoft Tavern
    Replies: 1
    Last Post: 09-09-2004, 09:07 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •