Results 1 to 8 of 8

Thread: path bug in 2.3

  1. #1

    Default path bug in 2.3

    Small bug results in not being able to make VirtualFileSystem work in an other path than the current one.

    !Patch isn't checked for compiling etc. issues.
    Attached Files Attached Files

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

    Default

    Please can you have a look at ClanLib-2.x/Tests/Core/IOData

    It fails...

    Code:
    	CL_String str;
    	CL_VirtualFileSystem vfs("../../");
    	CL_VirtualDirectory dir(vfs, "Core/IOData");
    
    	CL_Console::write_line("   Function: CL_VirtualFileSystem get_file_system()");
    	CL_VirtualFileSystem vfs_test = dir.get_file_system();
    	if (vfs_test.is_null()) fail();
    
    	CL_Console::write_line("   Function: CL_String &get_path()");
    	CL_String strpath = dir.get_path();
    	if (strpath != "Core/IOData/") fail();
    
    	CL_Console::write_line("   Function: CL_VirtualDirectoryListing get_directory_listing()");
    	CL_VirtualDirectoryListing listing = dir.get_directory_listing();
    The last line throws an exception "Cannot scan directory to initialize CL_VirtualDirectoryListing"

    from the patched ClanLib function

    Code:
    bool CL_VirtualFileSource_File::initialize_directory_listing(const CL_String &additionalpath)
    {
    	return dir_scanner.scan(CL_PathHelp::combine(this->path, additionalpath));
    }
    It is possible that the test is wrong, but I have not got the time to check

  3. #3

    Default

    I currently don't have the time to look into it either and my Tests don't compile with make because of directory issues (maybe not correctly set by autohell)?

    My problem was that vfs.has_file() failed. Which the patch fixes. So maybe I corrected in the wrong place.

  4. #4

    Default

    I rechecked. And corrected the code.

    I think I did it right as it shouldn't be the job of CL_VirtualDirectory to know about the internals of path working in the CL_VirtualFileSystem.
    But maybe it was a design decision.

    VirtualFileSystem::has_file doesn't go this code path over CL_VirtualDirectory when creating a CL_VirtualDirectoryListening so I think it should be the right solution.

    But maybe I break code for VirtualFileSystems being Zip files. Somebody has to check!

    And there should be a Test for VirtualFileSystem::has_file in the virtual_directory_test
    Attached Files Attached Files
    Last edited by gpmfuchs; 11-22-2011 at 03:06 AM.

  5. #5
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    In my opinion, the patch is correct.

    I have applied the patch to ClanLib 2.4 svn for others to look at (before applying it to 2.3)

    The ".zip" functions appear broken (nothing to do with the patch)

    For example: (Tests/Core/IOData)

    Code:
    void TestApp::test_vfs()
    {
    	while(true)
    	{
    		if (dir.get_filename() == "IOData")
    			break;
    		if (!dir.next())
    			fail();
    	}
    	if (!dir.is_directory())
    		fail();
    
    	CL_VirtualFileSystem vfs2("test.zip", true);
    	CL_VirtualDirectoryListing dir2 = vfs2.get_directory_listing("FolderA");
    
    	while(true)
    	{
    		CL_String filename = dir2.get_filename();
    		if (filename == "FolderTest")
    			break;
    		if (!dir2.next())
    			fail();
    	}
    	if (!dir2.is_directory())
    		fail();
    
    }
    CL_ZipArchive::get_file_list() looks very wrong... so wrong that I think I must be wrong

  6. #6

    Default

    Rombust was asking in IRC how I had used the VFS & ZIP classes...

    Code:
    	if (vfs2.has_directory("FolderA"))
    	{
    		CL_VirtualDirectory vdir = vfs2.open_directory("FolderA");
    		CL_VirtualDirectoryListing vlist = vdir.get_directory_listing();
    
    		while (vlist.next())
    		{
    			CL_String filename = vlist.get_filename();
    			if (filename == "FolderTest")
    				break;
    		}
    
    		if (!vlist.is_directory())
    			fail();
    	}
    This method is still working. The code in the IOData test does seem to misbehave quite badly. Notice the difference in while(true) vs. while (vlist.next()). I'm not sure if you get anything valid before calling next() once?

  7. #7

    Default

    I'm not sure. But shouldn't there be a fail() in case of the last vlist.next() being false.
    I don't know how "save" is_directory() is implemented that it will trigger fail(),
    but for example is_writeable() or is_readable() is broken for directories in windows.

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Many thanks to you all.

    The problem was that "CL_ZipArchive::get_file_list(const CL_StringRef &dirpath)"
    expected "dirpath" to be absolute with a trailing slash.

    So by adding
    Code:
    path = CL_PathHelp::make_absolute("/", path, CL_PathHelp::path_type_virtual);
    path = CL_PathHelp::add_trailing_slash(path, CL_PathHelp::path_type_virtual);
    fixes it (even if it was already absolute and had a trailing slash)

    I have updated the IOTest, testing the various methods of obtaining the directory listing (including the dir.next() bug harry spotted).

    Committed to ClanLib 2.3 and 2.4 SVN.

    Many thanks.

Similar Threads

  1. Simple Path Movement
    By Pleng in forum Novashell Game Creation System
    Replies: 11
    Last Post: 03-22-2008, 11:30 AM
  2. Relative File Path
    By Dr. Rain in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 03-08-2008, 01:05 AM

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
  •