Handle error returns from lstat.

This commit is contained in:
Jeff Young 2020-01-13 20:03:53 +00:00
parent 9df2cfb328
commit 1bdcb33f75
1 changed files with 29 additions and 14 deletions

View File

@ -865,25 +865,40 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
std::string entry_path = dir_path + '/' + dir_entry->d_name; std::string entry_path = dir_path + '/' + dir_entry->d_name;
struct stat entry_stat; struct stat entry_stat;
wxCRT_Lstat( entry_path.c_str(), &entry_stat ); if( wxCRT_Lstat( entry_path.c_str(), &entry_stat ) == 0 )
// Timestamp the source file, not the symlink
if( S_ISLNK( entry_stat.st_mode ) ) // wxFILE_EXISTS_SYMLINK
{ {
char buffer[ PATH_MAX + 1 ]; // Timestamp the source file, not the symlink
ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX ); if( S_ISLNK( entry_stat.st_mode ) ) // wxFILE_EXISTS_SYMLINK
if( pathLen > 0 )
{ {
buffer[ pathLen ] = '\0'; char buffer[ PATH_MAX + 1 ];
entry_path = dir_path + buffer; ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
wxCRT_Lstat( entry_path.c_str(), &entry_stat ); if( pathLen > 0 )
{
struct stat linked_stat;
buffer[ pathLen ] = '\0';
entry_path = dir_path + buffer;
if( wxCRT_Lstat( entry_path.c_str(), &linked_stat ) == 0 )
{
entry_stat = linked_stat;
}
else
{
// if we couldn't lstat the linked file we'll have to just use
// the symbolic link info
}
}
} }
}
if( S_ISREG( entry_stat.st_mode ) ) // wxFileExists() if( S_ISREG( entry_stat.st_mode ) ) // wxFileExists()
timestamp += entry_stat.st_mtime * 1000; timestamp += entry_stat.st_mtime * 1000;
}
else
{
// if we couldn't lstat the file itself all we can do is use the name
timestamp += (signed) std::hash<std::string>{}( std::string( dir_entry->d_name ) );
}
} }
closedir( dir ); closedir( dir );