2018-03-19 15:08 EDT

View Issue Details Jump to Notes ] Related Changesets ]
IDProjectCategoryView StatusLast Update
0003036FSSCPPlatform-Engine interactionpublic2015-01-22 14:29
Assigned Tochief1983 
PlatformOSLinuxOS Version
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.


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.
Attached Files
  • 7z file icon mantis3036_mod.7z (1,193 bytes) 2014-05-08 23:46
  • diff file icon 3036_proposed.diff (1,105 bytes) 2015-01-18 22:34 -
    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
    diff file icon 3036_proposed.diff (1,105 bytes) 2015-01-18 22:34 +




chief1983 (administrator)

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 (administrator)

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 (administrator)

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 (developer)

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


chief1983 (administrator)

Fix committed to trunk@11222.

+Related Changesets

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