[Scummvm-cvs-logs] SF.net SVN: scummvm: [22171] scummvm/trunk/common/file.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Apr 26 01:30:01 CEST 2006


Revision: 22171
Author:   fingolfin
Date:     2006-04-26 01:29:32 -0700 (Wed, 26 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22171&view=rev

Log Message:
-----------
Yet another revision of File::exists. I now believe the function really is 'wrong' right now (it has to fulfill too many roles right now). Need to correctly fix this later

Modified Paths:
--------------
    scummvm/trunk/common/file.cpp
Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp	2006-04-26 08:13:25 UTC (rev 22170)
+++ scummvm/trunk/common/file.cpp	2006-04-26 08:29:32 UTC (rev 22171)
@@ -263,8 +263,34 @@
 }
 
 bool File::exists(const String &filename) {
+	// First try to find the file it via a FilesystemNode (in case an absolute
+	// path was passed). But we only use this to filter out directories.
 	FilesystemNode file(filename);
-	return (file.isValid() && !file.isDirectory());
+	if (file.isValid() && file.isDirectory())
+		return false;
+
+	// Next, try to locate the file by *opening* it in read mode. This has
+	// multiple effects:
+	// 1) It takes _filesMap and _defaultDirectories into consideration -> good
+	// 2) It returns true if and only if File::open is possible on the file -> good
+	// 3) If this method is misused, it could lead to an fopen call on a directory
+	//    -> bad!
+	// 4) It also checks whether we can read the file. This is not 100%
+	//    desirable; after all, even when we can't read it, the file is present.
+	//    Since this method is often used to check whether a file should be
+	//    re-created, that's not nice.
+	//
+	// TODO/FIXME: We should clarify the semantics of this method, and then
+	// maybe should introduce several new methods:
+	//   fileExistsAndReadable
+	//   fileExists
+	//   fileExistsAtPath
+	//   dirExists
+	//   dirExistsAtPath
+	// or maybe only 1-2 methods which take some params :-).
+	
+	File tmp;
+	return tmp.open(filename, kFileReadMode);
 }
 
 void File::close() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list