Fix symlink read-/write-through code
Use `realpath(3)` instead of `readlink(3)`, which offers support for relative and absolute symlinks alike, since all symbolic links will be resolved to the absolute path of the linked-to file. Fixes #8082
This commit is contained in:
parent
adea5842da
commit
06e967354f
|
@ -1384,15 +1384,11 @@ wxFileName SCH_SEXPR_PLUGIN_CACHE::GetRealFile() const
|
|||
#ifndef __WINDOWS__
|
||||
if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
|
||||
{
|
||||
char buffer[ PATH_MAX + 1 ];
|
||||
ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
|
||||
char buffer[ PATH_MAX ];
|
||||
char *realPath = realpath( TO_UTF8( fn.GetFullPath() ), buffer );
|
||||
|
||||
if( pathLen > 0 )
|
||||
{
|
||||
buffer[ pathLen ] = '\0';
|
||||
fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
|
||||
fn.Normalize();
|
||||
}
|
||||
if( realPath )
|
||||
fn.Assign( wxString::FromUTF8( realPath ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2441,15 +2441,11 @@ wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile() const
|
|||
#ifndef __WINDOWS__
|
||||
if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
|
||||
{
|
||||
char buffer[ PATH_MAX + 1 ];
|
||||
ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
|
||||
char buffer[ PATH_MAX ];
|
||||
char *realPath = realpath( TO_UTF8( fn.GetFullPath() ), buffer );
|
||||
|
||||
if( pathLen > 0 )
|
||||
{
|
||||
buffer[ pathLen ] = '\0';
|
||||
fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
|
||||
fn.Normalize();
|
||||
}
|
||||
if( realPath )
|
||||
fn.Assign( wxString::FromUTF8( realPath ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2409,15 +2409,11 @@ void PCB_IO::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFoot
|
|||
// Write through symlinks, don't replace them
|
||||
if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
|
||||
{
|
||||
char buffer[ PATH_MAX + 1 ];
|
||||
ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
|
||||
char buffer[ PATH_MAX ];
|
||||
char *realPath = realpath( TO_UTF8( fn.GetFullPath() ), buffer );
|
||||
|
||||
if( pathLen > 0 )
|
||||
{
|
||||
buffer[ pathLen ] = '\0';
|
||||
fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
|
||||
fn.Normalize();
|
||||
}
|
||||
if( realPath )
|
||||
fn.Assign( wxString::FromUTF8( realPath ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue