25#include <wx/filename.h>
41 FILE* fp = wxFopen( aPath, aMode );
45 if( posix_fadvise( fileno( fp ), 0, 0, POSIX_FADV_SEQUENTIAL ) != 0 )
57 struct stat sourceStat;
58 if( stat( aSrc.fn_str(), &sourceStat ) == 0 )
60 mode_t permissions = sourceStat.st_mode & ( S_IRWXU | S_IRWXG | S_IRWXO );
61 if( chmod( aDest.fn_str(), permissions ) == 0 )
81 if( stat( aFilePath.fn_str(), &fileStat ) == 0 )
84 mode_t newPermissions = fileStat.st_mode | S_IWUSR;
85 if( chmod( aFilePath.fn_str(), newPermissions ) == 0 )
111 wxFileName fn( aFileName );
113 return fn.GetName().StartsWith( wxT(
"." ) );
125 long long timestamp = 0;
127 std::string pattern( aFilespec.fn_str() );
128 std::string dir_path( aDirPath.fn_str() );
130 DIR* dir = opendir( dir_path.c_str() );
134 for( dirent* dir_entry = readdir( dir ); dir_entry; dir_entry = readdir( dir ) )
137 if( fnmatch( pattern.c_str(), dir_entry->d_name, FNM_CASEFOLD | FNM_PERIOD ) != 0 )
140 std::string entry_path = dir_path +
'/' + dir_entry->d_name;
141 struct stat entry_stat;
143 if( lstat( entry_path.c_str(), &entry_stat ) == 0 )
146 if( S_ISLNK( entry_stat.st_mode ) )
148 char buffer[PATH_MAX + 1];
149 ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
153 struct stat linked_stat;
154 buffer[pathLen] =
'\0';
155 std::string linked_path = dir_path +
'/' + buffer;
157 if( lstat( linked_path.c_str(), &linked_stat ) == 0 )
158 entry_stat = linked_stat;
162 if( S_ISREG( entry_stat.st_mode ) )
164 timestamp += entry_stat.st_mtime * 1000;
165 timestamp += entry_stat.st_size;
171 timestamp += (signed) std::hash<std::string>{}( std::string( dir_entry->d_name ) );
187 if( std::fflush( aFp ) != 0 )
190 int fd = fileno( aFp );
195 return fsync( fd ) == 0;
201 int fd = open( aFileName.fn_str(), O_RDONLY );
205 throw std::runtime_error( std::string(
"Cannot open file: " )
206 + aFileName.ToStdString() );
211 if( fstat( fd, &st ) != 0 )
214 throw std::runtime_error( std::string(
"Cannot stat file: " )
215 + aFileName.ToStdString() );
218 m_size =
static_cast<size_t>( st.st_size );
226 void* ptr = mmap(
nullptr,
m_size, PROT_READ, MAP_PRIVATE, fd, 0 );
229 if( ptr == MAP_FAILED )
235 madvise( ptr,
m_size, MADV_SEQUENTIAL );
236 m_data =
static_cast<const uint8_t*
>( ptr );