Skip to content

Commit 0049294

Browse files
committed
Merge branch 'release-6.6.4' into develop
2 parents fcc6747 + 5c579db commit 0049294

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

engine/src/osxfiles.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,33 @@ static char *my_strndup(const char *s, uint32_t l)
100100

101101
// File opening and closing
102102

103+
// This function checks that a file really does exist at the given location.
104+
// The path is expected to have been resolved but in native encoding.
105+
static bool MCS_file_exists_at_path(const char *path)
106+
{
107+
char *newpath = path2utf(strdup(path));
108+
109+
bool t_found;
110+
111+
struct stat buf;
112+
t_found = (stat(newpath, (struct stat *)&buf) == 0);
113+
if (t_found)
114+
if ((buf . st_mode & S_IFDIR) != 0)
115+
t_found = false;
116+
117+
delete newpath;
118+
119+
return t_found;
120+
}
121+
103122
// MW-2014-09-17: [[ Bug 13455 ]] Attempt to redirect path. If p_is_file is false,
104123
// the path is taken to be a directory and is always redirected if is within
105124
// Contents/MacOS. If p_is_file is true, then the file is only redirected if
106125
// the original doesn't exist, and the redirection does.
107-
bool MCS_apply_redirect(char*& x_path, bool p_is_file)
126+
static bool MCS_apply_redirect(char*& x_path, bool p_is_file)
108127
{
109128
// If the original file exists, do nothing.
110-
if (p_is_file && MCS_exists(x_path, p_is_file))
129+
if (p_is_file && MCS_file_exists_at_path(x_path))
111130
return false;
112131

113132
int t_engine_path_length;
@@ -133,7 +152,7 @@ bool MCS_apply_redirect(char*& x_path, bool p_is_file)
133152
char *t_new_path;
134153
/* UNCHECKED */ MCCStringFormat(t_new_path, "%.*s/Resources/_MacOS/%s", t_engine_path_length - 6, MCcmd, x_path + t_engine_path_length);
135154

136-
if (p_is_file && !MCS_exists(x_path, p_is_file))
155+
if (p_is_file && !MCS_file_exists_at_path(t_new_path))
137156
{
138157
free(t_new_path);
139158
return false;
@@ -683,9 +702,11 @@ Boolean MCS_exists(const char *path, Boolean file)
683702
if (t_resolved_path == NULL)
684703
return False;
685704

705+
if (file)
706+
MCS_apply_redirect(t_resolved_path, file);
707+
686708
char *newpath = path2utf(t_resolved_path);
687709

688-
689710
struct stat buf;
690711
found = stat(newpath, (struct stat *)&buf) == 0;
691712
if (found)

0 commit comments

Comments
 (0)