@@ -2050,36 +2050,35 @@ class MCLinuxDesktop: public MCSystemInterface
20502050 }
20512051 delete tpath;
20522052 }
2053+ else if (path[0 ] != ' /' )
2054+ {
2055+ // SN-2015-06-05: [[ Bug 15432 ]] Fix resolvepath on Linux: we want an
2056+ // absolute path.
2057+ char *t_curfolder;
2058+ t_curfolder = MCS_getcurdir ();
2059+ tildepath = new char [strlen (t_curfolder) + strlen (path) + 2 ];
2060+ /* UNCHECKED */ sprintf (tildepath, " %s/%s" , t_curfolder, path);
2061+
2062+ delete t_curfolder;
2063+ }
20532064 else
20542065 tildepath = strclone (path);
20552066
20562067 struct stat64 buf;
20572068 if (lstat64 (tildepath, &buf) != 0 || !S_ISLNK (buf.st_mode ))
20582069 return tildepath;
2059- int4 size;
2070+
20602071 char *newname = new char [PATH_MAX + 2 ];
2061- if ((size = readlink (tildepath, newname, PATH_MAX)) < 0 )
2072+
2073+ // SN-2015-06-05: [[ Bug 15432 ]] Use realpath to solve the symlink.
2074+ if (realpath (tildepath, newname) == NULL )
20622075 {
2063- delete tildepath;
2076+ // Clear the memory in case of failure
20642077 delete newname;
2065- return NULL ;
2078+ newname = NULL ;
20662079 }
2080+
20672081 delete tildepath;
2068- newname[size] = ' \0 ' ;
2069- if (newname[0 ] != ' /' )
2070- {
2071- char *fullpath = new char [strlen (path) + strlen (newname) + 2 ];
2072- strcpy (fullpath, path);
2073- char *sptr = strrchr (fullpath, ' /' );
2074- if (sptr == NULL )
2075- sptr = fullpath;
2076- else
2077- sptr++;
2078- strcpy (sptr, newname);
2079- delete newname;
2080- newname = MCS_resolvepath (fullpath);
2081- delete fullpath;
2082- }
20832082 return newname;
20842083#endif /* MCS_resolvepath_dsk_lnx */
20852084 if (MCStringGetLength (p_path) == 0 )
@@ -2124,12 +2123,28 @@ class MCLinuxDesktop: public MCSystemInterface
21242123 else
21252124 t_tilde_path = p_path;
21262125 }
2126+ else if (MCStringGetNativeCharAtIndex (p_path, 0 ) != ' /' )
2127+ {
2128+ // SN-2015-06-05: [[ Bug 15432 ]] Fix resolvepath on Linux: we want an
2129+ // absolute path.
2130+ MCAutoStringRef t_curdir;
2131+ MCS_getcurdir (&t_curdir);
2132+
2133+ if (!MCStringFormat (&t_tilde_path, " %@/%@" , *t_curdir, p_path))
2134+ return false ;
2135+ }
21272136 else
21282137 t_tilde_path = p_path;
21292138
21302139 // SN-2014-12-18: [[ Bug 14001 ]] Update the server file resolution to use realpath
21312140 // so that we get the absolute path (needed for MCcmd for instance).
2132- #ifdef _SERVER
2141+ // SN-2015-06-08: Use realpath on desktop as well.
2142+ #ifndef _SERVER
2143+ // IM-2012-07-23
2144+ // Keep (somewhat odd) semantics of the original function for now
2145+ if (!MCS_lnx_is_link (*t_tilde_path))
2146+ return MCStringCopy (*t_tilde_path, r_resolved_path);
2147+ #endif
21332148 MCAutoStringRefAsSysString t_tilde_path_sys;
21342149 t_tilde_path_sys . Lock (*t_tilde_path);
21352150
@@ -2144,45 +2159,11 @@ class MCLinuxDesktop: public MCSystemInterface
21442159 if (t_resolved_path != NULL )
21452160 t_success = MCStringCreateWithSysString (t_resolved_path, r_resolved_path);
21462161 else
2147- t_success = MCStringCopy (*t_tilde_path, r_resolved_path) ;
2162+ t_success = false ;
21482163
21492164 MCMemoryDelete (t_resolved_path);
21502165
21512166 return t_success;
2152- #else
2153-
2154- // IM-2012-07-23
2155- // Keep (somewhat odd) semantics of the original function for now
2156- if (!MCS_lnx_is_link (*t_tilde_path))
2157- return MCStringCopy (*t_tilde_path, r_resolved_path);
2158-
2159- MCAutoStringRef t_newname;
2160- if (!MCS_lnx_readlink (*t_tilde_path, &t_newname))
2161- return false ;
2162-
2163- if (MCStringGetCharAtIndex (*t_newname, 0 ) != ' /' )
2164- {
2165- MCAutoStringRef t_resolved;
2166-
2167- uindex_t t_last_component;
2168- uindex_t t_path_length;
2169-
2170- t_path_length = MCStringGetLength (p_path);
2171-
2172- if (MCStringLastIndexOfChar (p_path, ' /' , t_path_length, kMCStringOptionCompareExact , t_last_component))
2173- t_last_component++;
2174- else
2175- t_last_component = 0 ;
2176-
2177- if (!MCStringMutableCopySubstring (p_path, MCRangeMake (0 , t_last_component), &t_resolved) ||
2178- !MCStringAppend (*t_resolved, *t_newname))
2179- return false ;
2180-
2181- return MCStringCopy (*t_resolved, r_resolved_path);
2182- }
2183- else
2184- return MCStringCopy (*t_newname, r_resolved_path);
2185- #endif
21862167 }
21872168
21882169 virtual bool LongFilePath (MCStringRef p_path, MCStringRef& r_long_path)
0 commit comments