View Issue Details

IDProjectCategoryView StatusLast Update
0003036FSSCPPlatform-Engine interactionpublic2015-01-22 19:29
Reporterniffiwan Assigned Tochief1983  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
OSLinux 
Product Version3.7.1 
Target Version3.7.2Fixed in Version3.7.2 RC5 
Summary0003036: cf_exists does not search all dirs correctly on Linux (and probably OSX)
DescriptionPretty much as it says. On Linux/OSX, some "directories" have two locations.

i.e.
mod/data/config
~/.fs2_open/mod/data/config

cf_exists will only find files in the 2nd location, even though valid files may be in the 1st location. It should probably search both locations, with the 2nd one having precedence.

Definitely affects CF_TYPE_CONFIG, may affect other types as well.

===========================

Note: cf_exists_full correctly (?? maybe, haven't checked precedence) finds files in both locations.
Steps To ReproduceSee attached mod.

Press enter in the mainhall (or anywhere) to run a script that attempts to open test files in nearly all known locations.
Failure to open the file generates a warning.
Switch the cf.fileExists() 3rd param to true and all files will be found.
Add the relevant files to the relevant directories in ~/.fs_open/ and the files will be found.
Additional InformationFound when using LUA cf.fileExists() with the 3rd param set to false. Note that setting the 3rd param to true is a workaround.
TagsNo tags attached.

Activities

niffiwan

2014-05-09 03:46

developer  

mantis3036_mod.7z (1,193 bytes)

chief1983

2015-01-19 03:34

administrator  

3036_proposed.diff (1,105 bytes)   
Index: code/cfile/cfile.cpp
===================================================================
--- code/cfile/cfile.cpp	(revision 11218)
+++ code/cfile/cfile.cpp	(working copy)
@@ -492,23 +492,17 @@
 
 // Returns 1 if the file exists, 0 if not.
 // Checks only the file system.
+// cf_find_file_location checks the filesystem before VPs
+// If offset is 0, it was found in the filesystem, so offset is boolean false
+// If offset equates to boolean true, it was found in a VP and the logic will negate the function return
 int cf_exists(const char *filename, int dir_type)
 {
-	char longname[MAX_PATH_LEN];
+	int offset = 1;
 
-	Assert(CF_TYPE_SPECIFIED(dir_type));
+	if ( (filename == NULL) || !strlen(filename) )
+		return 0;
 
-	cf_create_default_path_string(longname, sizeof(longname) - 1, dir_type, filename);
-
-	FILE *fp = fopen(longname, "rb");
-	if (fp)
-	{
-		// Goober5000 - these were switched, causing the fclose to be unreachable
-		fclose(fp);
-		return 1;
-	}
-
-	return 0;
+	return (cf_find_file_location(filename, dir_type, 0, NULL, &offset, NULL) && !offset);
 }
 
 // Goober5000
3036_proposed.diff (1,105 bytes)   

chief1983

2015-01-19 03:35

administrator   ~0016455

I've attached a patch which should fix this issue, by causing this function to use the same lower level function as the other cf_exists* family of functions. This should simplify the code as a result, if there are no adverse effects from this behavior change. Since the behavioral difference appears to have been platform-specific, I don't anticipate issues.

chief1983

2015-01-19 03:40

administrator   ~0016456

Update the steps to reproduce with what I believe is a typo fix since cf_exists doesn't have 3 arguments but the referenced Lua counterpart does.

chief1983

2015-01-19 03:41

administrator   ~0016457

Patch doesn't seem to cause any issues for me on Windows with the MediaVPs and my recent trunk build, will test OS X tomorrow. Would like to hear results of general purpose gameplay testing and the mod test from a Linux user before I commit.

niffiwan

2015-01-20 09:22

developer   ~0016458

Works fine on Linux both playing a mission with mediavps_2014 & running the attached test mod.

chief1983

2015-01-22 19:21

administrator   ~0016459

Fix committed to trunk@11222.

Related Changesets

fs2open: trunk r11222

2015-01-22 14:30

chief1983


Ported: N/A

Details Diff
Fix for Mantis 3036: This unifies the cf_exists function to behave like the other functions in the cf_exists* family, and simultaneously addresses the bug. Affected Issues
0003036
mod - /trunk/fs2_open/code/cfile/cfile.cpp Diff File

Issue History

Date Modified Username Field Change
2014-04-30 04:30 niffiwan New Issue
2014-04-30 06:00 niffiwan Description Updated
2014-04-30 06:00 niffiwan Additional Information Updated
2014-05-09 03:46 niffiwan File Added: mantis3036_mod.7z
2014-05-09 03:49 niffiwan Steps to Reproduce Updated
2015-01-19 03:33 chief1983 Assigned To => chief1983
2015-01-19 03:33 chief1983 Status new => assigned
2015-01-19 03:34 chief1983 File Added: 3036_proposed.diff
2015-01-19 03:35 chief1983 Note Added: 0016455
2015-01-19 03:36 chief1983 Status assigned => code review
2015-01-19 03:40 chief1983 Note Added: 0016456
2015-01-19 03:40 chief1983 Steps to Reproduce Updated
2015-01-19 03:41 chief1983 Note Added: 0016457
2015-01-20 09:22 niffiwan Note Added: 0016458
2015-01-22 19:21 chief1983 Changeset attached => fs2open trunk r11222
2015-01-22 19:21 chief1983 Note Added: 0016459
2015-01-22 19:21 chief1983 Status code review => resolved
2015-01-22 19:21 chief1983 Resolution open => fixed
2015-01-22 19:29 chief1983 Fixed in Version => 3.7.2 RC5
2015-01-22 19:29 chief1983 Target Version => 3.7.2