106 long long timestamp = 0;
108 std::string pattern( aFilespec.fn_str() );
109 std::string dir_path( aDirPath.fn_str() );
111 DIR* dir = opendir( dir_path.c_str() );
115 for( dirent* dir_entry = readdir( dir ); dir_entry; dir_entry = readdir( dir ) )
118 if( fnmatch( pattern.c_str(), dir_entry->d_name, FNM_CASEFOLD | FNM_PERIOD ) != 0 )
121 std::string entry_path = dir_path +
'/' + dir_entry->d_name;
122 struct stat entry_stat;
124 if( lstat( entry_path.c_str(), &entry_stat ) == 0 )
127 if( S_ISLNK( entry_stat.st_mode ) )
129 char buffer[PATH_MAX + 1];
130 ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
134 struct stat linked_stat;
135 buffer[pathLen] =
'\0';
136 std::string linked_path = dir_path +
'/' + buffer;
138 if( lstat( linked_path.c_str(), &linked_stat ) == 0 )
139 entry_stat = linked_stat;
143 if( S_ISREG( entry_stat.st_mode ) )
145 timestamp += entry_stat.st_mtime * 1000;
146 timestamp += entry_stat.st_size;
152 timestamp += (signed) std::hash<std::string>{}( std::string( dir_entry->d_name ) );
165 int fd = open( aFileName.fn_str(), O_RDONLY );
169 throw std::runtime_error( std::string(
"Cannot open file: " )
170 + aFileName.ToStdString() );
175 if( fstat( fd, &st ) != 0 )
178 throw std::runtime_error( std::string(
"Cannot stat file: " )
179 + aFileName.ToStdString() );
182 m_size =
static_cast<size_t>( st.st_size );
190 void* ptr = mmap(
nullptr,
m_size, PROT_READ, MAP_PRIVATE, fd, 0 );
193 if( ptr == MAP_FAILED )
199 madvise( ptr,
m_size, MADV_SEQUENTIAL );
200 m_data =
static_cast<const uint8_t*
>( ptr );