@@ -820,10 +820,14 @@ class Page
820
820
while ( (d=readdir (dir))!=0 )
821
821
{
822
822
std::string subject=join_path (directory,d->d_name );
823
- const char * file = subject.c_str ();
823
+ int fd = open ( subject.c_str (), O_RDONLY );
824
824
825
- if (stat (file, &statbuf) ==- 1 )
825
+ if (fd < 0 )
826
826
continue ;
827
+ if (fstat (fd, &statbuf) ==-1 ) {
828
+ close (fd);
829
+ continue ;
830
+ }
827
831
if (S_ISDIR (statbuf.st_mode ))
828
832
{
829
833
if ( (strcmp (d->d_name ," ." )!=0 ) && (strcmp (d->d_name ," .." )!=0 ) )
@@ -836,9 +840,7 @@ class Page
836
840
else
837
841
{
838
842
bool found = false ;
839
- std::string str = subject;
840
- transform (str.begin (), str.end (),str.begin (), tolower );
841
- FILE *fp = fopen (file, " rb" );
843
+ FILE *fp = fdopen (fd, " rb" );
842
844
if (fp)
843
845
{
844
846
Pcap_file pfile (fp);
@@ -866,10 +868,10 @@ class Page
866
868
printf (" %c{\n \" data\" : \" %s\" ,\n \" attr\" : { \" id\" : \" %s\" , \" size\" : %d, \" type\" : \" json\" },\n \" children\" : [] }\n " ,
867
869
comma,d->d_name ,join_path (m_url.get_path (),d->d_name ).substr (5 ).c_str (), int (statbuf.st_size ) );
868
870
comma= ' ,' ;
869
- found = true ;
870
871
}
871
872
}
872
873
}
874
+ close (fd);
873
875
}
874
876
875
877
printf (" ]\n " );
0 commit comments