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
Bookmarks