@@ -34,7 +34,7 @@ const bool CFileLister::list(const std::string &p_path)
3434 // Read dir
3535 std::string l_file (" " );
3636 std::string l_fileFull (" " );
37- struct stat l_stat ;
37+ struct stat st ;
3838 struct dirent *l_dirent = readdir (l_dir);
3939 while (l_dirent != NULL )
4040 {
@@ -44,19 +44,29 @@ const bool CFileLister::list(const std::string &p_path)
4444 {
4545 // Stat the file
4646 l_fileFull = p_path + " /" + l_file;
47- if (stat (l_fileFull.c_str (), &l_stat ) == -1 )
47+ if (lstat (l_fileFull.c_str (), &st ) == -1 )
4848 {
49- std::cerr << " CFileLister::list: Error stat " << l_fileFull << std::endl;
49+ std::cerr << " CFileLister::list: Error lstat " << l_fileFull << std::endl;
5050 }
5151 else
5252 {
53+ const bool is_symlink = S_ISLNK (st.st_mode );
54+ auto tfile = T_FILE (l_file, is_symlink);
55+ if (tfile.is_symlink ) {
56+ // Follow the link.
57+ if (stat (l_fileFull.c_str (), &st) == -1 ) {
58+ st.st_size = 0 ; // Invalid symlink.
59+ }
60+ }
61+ tfile.m_size = st.st_size ;
62+
5363 // Check type
54- if (S_ISDIR (l_stat .st_mode ))
64+ if (S_ISDIR (st .st_mode ))
5565 // It's a directory
56- m_listDirs.push_back (T_FILE (l_file, l_stat. st_size ));
66+ m_listDirs.push_back (std::move (tfile ));
5767 else
5868 // It's a file
59- m_listFiles.push_back (T_FILE (l_file, l_stat. st_size ));
69+ m_listFiles.push_back (std::move (tfile ));
6070 }
6171 }
6272 // Next
@@ -68,7 +78,7 @@ const bool CFileLister::list(const std::string &p_path)
6878 sort (m_listFiles.begin (), m_listFiles.end (), compareNoCase);
6979 sort (m_listDirs.begin (), m_listDirs.end (), compareNoCase);
7080 // Add "..", always at the first place
71- m_listDirs.insert (m_listDirs.begin (), T_FILE (" .." , 0 ));
81+ m_listDirs.insert (m_listDirs.begin (), T_FILE (" .." , /* is_symlink= */ false , 0 ));
7282 return true ;
7383}
7484
0 commit comments