Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions source/funkin/util/FileUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FileUtil
*/
public static var PROTECTED_PATHS(get, never):Array<String>;

public static function get_PROTECTED_PATHS():Array<String>
static function get_PROTECTED_PATHS():Array<String>
{
final protected:Array<String> = [
'',
Expand All @@ -83,7 +83,8 @@ class FileUtil
#if sys
for (i in 0...protected.length)
{
protected[i] = sys.FileSystem.fullPath(Path.join([gameDirectory, protected[i]]));
// On Linux 'fullPath' just makes most of these null which actually just makes the paths unprotected
protected[i] = #if !linux sys.FileSystem.fullPath #end (Path.join([gameDirectory, protected[i]]));
}
#end

Expand Down Expand Up @@ -1306,8 +1307,26 @@ class FileUtilSandboxed

#if sys
// TODO: figure out how to get "real" path of symlinked paths
final realPath:String = sys.FileSystem.fullPath(Path.join([FileUtil.gameDirectory, sanitized.join('/')]));
if (!realPath.startsWith(FileUtil.gameDirectory))
#if linux
// The implementation on Linux fails if the path doesn't exist
var realPath:Null<String> = null;
var unresolvedSegments:Array<String> = [];
while (realPath == null && sanitized.length > 0)
{
realPath = sys.FileSystem.fullPath(Path.join([FileUtil.gameDirectory].concat(sanitized)));
if (realPath == null) unresolvedSegments.unshift(sanitized.pop() ?? continue);
}

if (unresolvedSegments.length > 0)
{
if (realPath != null) unresolvedSegments.unshift(realPath);
realPath = Path.join(unresolvedSegments);
}
#else
final realPath:Null<String> = sys.FileSystem.fullPath(Path.join([FileUtil.gameDirectory].concat(sanitized)));
#end

if (realPath == null || !realPath.startsWith(FileUtil.gameDirectory))
{
return FileUtil.gameDirectory;
}
Expand Down