@@ -2056,36 +2056,35 @@ class MCLinuxDesktop: public MCSystemInterface
20562056 }
20572057 delete tpath;
20582058 }
2059+ else if (path[0 ] != ' /' )
2060+ {
2061+ // SN-2015-06-05: [[ Bug 15432 ]] Fix resolvepath on Linux: we want an
2062+ // absolute path.
2063+ char *t_curfolder;
2064+ t_curfolder = MCS_getcurdir ();
2065+ tildepath = new char [strlen (t_curfolder) + strlen (path) + 2 ];
2066+ /* UNCHECKED */ sprintf (tildepath, " %s/%s" , t_curfolder, path);
2067+
2068+ delete t_curfolder;
2069+ }
20592070 else
20602071 tildepath = strclone (path);
20612072
20622073 struct stat64 buf;
20632074 if (lstat64 (tildepath, &buf) != 0 || !S_ISLNK (buf.st_mode ))
20642075 return tildepath;
2065- int4 size;
2076+
20662077 char *newname = new char [PATH_MAX + 2 ];
2067- if ((size = readlink (tildepath, newname, PATH_MAX)) < 0 )
2078+
2079+ // SN-2015-06-05: [[ Bug 15432 ]] Use realpath to solve the symlink.
2080+ if (realpath (tildepath, newname) == NULL )
20682081 {
2069- delete tildepath;
2082+ // Clear the memory in case of failure
20702083 delete newname;
2071- return NULL ;
2084+ newname = NULL ;
20722085 }
2086+
20732087 delete tildepath;
2074- newname[size] = ' \0 ' ;
2075- if (newname[0 ] != ' /' )
2076- {
2077- char *fullpath = new char [strlen (path) + strlen (newname) + 2 ];
2078- strcpy (fullpath, path);
2079- char *sptr = strrchr (fullpath, ' /' );
2080- if (sptr == NULL )
2081- sptr = fullpath;
2082- else
2083- sptr++;
2084- strcpy (sptr, newname);
2085- delete newname;
2086- newname = MCS_resolvepath (fullpath);
2087- delete fullpath;
2088- }
20892088 return newname;
20902089#endif /* MCS_resolvepath_dsk_lnx */
20912090 if (MCStringGetLength (p_path) == 0 )
@@ -2130,12 +2129,30 @@ class MCLinuxDesktop: public MCSystemInterface
21302129 else
21312130 t_tilde_path = p_path;
21322131 }
2132+ else if (MCStringGetNativeCharAtIndex (p_path, 0 ) != ' /' )
2133+ {
2134+ // SN-2015-06-05: [[ Bug 15432 ]] Fix resolvepath on Linux: we want an
2135+ // absolute path.
2136+ MCAutoStringRef t_curdir;
2137+ MCS_getcurdir (&t_curdir);
2138+
2139+ if (!MCStringFormat (&t_tilde_path, " %@/%@" , *t_curdir, p_path))
2140+ {
2141+ return false ;
2142+ }
2143+ }
21332144 else
21342145 t_tilde_path = p_path;
21352146
21362147 // SN-2014-12-18: [[ Bug 14001 ]] Update the server file resolution to use realpath
21372148 // so that we get the absolute path (needed for MCcmd for instance).
2138- #ifdef _SERVER
2149+ // SN-2015-06-08: Use realpath on desktop as well.
2150+ #ifndef _SERVER
2151+ // IM-2012-07-23
2152+ // Keep (somewhat odd) semantics of the original function for now
2153+ if (!MCS_lnx_is_link (*t_tilde_path))
2154+ return MCStringCopy (*t_tilde_path, r_resolved_path);
2155+ #endif
21392156 MCAutoStringRefAsSysString t_tilde_path_sys;
21402157 t_tilde_path_sys . Lock (*t_tilde_path);
21412158
@@ -2155,40 +2172,6 @@ class MCLinuxDesktop: public MCSystemInterface
21552172 MCMemoryDelete (t_resolved_path);
21562173
21572174 return t_success;
2158- #else
2159-
2160- // IM-2012-07-23
2161- // Keep (somewhat odd) semantics of the original function for now
2162- if (!MCS_lnx_is_link (*t_tilde_path))
2163- return MCStringCopy (*t_tilde_path, r_resolved_path);
2164-
2165- MCAutoStringRef t_newname;
2166- if (!MCS_lnx_readlink (*t_tilde_path, &t_newname))
2167- return false ;
2168-
2169- if (MCStringGetCharAtIndex (*t_newname, 0 ) != ' /' )
2170- {
2171- MCAutoStringRef t_resolved;
2172-
2173- uindex_t t_last_component;
2174- uindex_t t_path_length;
2175-
2176- t_path_length = MCStringGetLength (p_path);
2177-
2178- if (MCStringLastIndexOfChar (p_path, ' /' , t_path_length, kMCStringOptionCompareExact , t_last_component))
2179- t_last_component++;
2180- else
2181- t_last_component = 0 ;
2182-
2183- if (!MCStringMutableCopySubstring (p_path, MCRangeMake (0 , t_last_component), &t_resolved) ||
2184- !MCStringAppend (*t_resolved, *t_newname))
2185- return false ;
2186-
2187- return MCStringCopy (*t_resolved, r_resolved_path);
2188- }
2189- else
2190- return MCStringCopy (*t_newname, r_resolved_path);
2191- #endif
21922175 }
21932176
21942177 virtual bool LongFilePath (MCStringRef p_path, MCStringRef& r_long_path)
0 commit comments