@@ -286,13 +286,13 @@ size_t OSUtil::getDirectorySize(const std::string &Path) {
286
286
// Use ftw for Linux and darwin as they support posix.
287
287
#if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
288
288
auto SumSize = []([[maybe_unused]] const char *Fpath,
289
- const struct stat *StatBuf, [[maybe_unused]] int TypeFlag) {
289
+ const struct stat *StatBuf, int TypeFlag) {
290
290
if (TypeFlag == FTW_F)
291
291
DirSizeVar += StatBuf->st_size ;
292
292
return 0 ;
293
293
};
294
294
295
- if (ftw (Path.c_str (),SumSize, 1 ) == -1 )
295
+ if (ftw (Path.c_str (), SumSize, 1 ) == -1 )
296
296
std::cerr << " Failed to get directory size: " << Path << std::endl;
297
297
#endif
298
298
@@ -302,43 +302,44 @@ size_t OSUtil::getDirectorySize(const std::string &Path) {
302
302
// Get size of file in bytes.
303
303
size_t OSUtil::getFileSize (const std::string &Path) {
304
304
size_t Size = 0 ;
305
- #if __GNUC__ && __GNUC__ < 8
306
- // Should we worry about this case?
307
- assert (false && " getFileSize is not implemented for GCC < 8" );
308
- #else
309
- std::filesystem::path FilePath (Path);
310
- if (std::filesystem::exists (FilePath) &&
311
- std::filesystem::is_regular_file (FilePath))
312
- Size = std::filesystem::file_size (FilePath);
313
- #endif
305
+
306
+ // For POSIX, use stats to get file size.
307
+ #if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
308
+ struct stat StatBuf;
309
+ if (stat (Path.c_str (), &StatBuf) == 0 )
310
+ Size = StatBuf.st_size ;
311
+
312
+ // For Windows, use GetFileAttributesEx to get file size.
313
+ #elif defined(__SYCL_RT_OS_WINDOWS)
314
+ WIN32_FILE_ATTRIBUTE_DATA FileData;
315
+ if (GetFileAttributesEx (Path.c_str (), GetFileExInfoStandard, &FileData))
316
+ Size = (static_cast <size_t >(FileData.nFileSizeHigh ) << 32 ) |
317
+ FileData.nFileSizeLow ;
318
+ #endif // __SYCL_RT_OS
319
+
314
320
return Size ;
315
321
}
316
322
323
+ std::vector<std::pair<time_t , std::string>> OSUtil::Files = {};
317
324
// Get list of all files in the directory along with its last access time.
318
325
std::vector<std::pair<time_t , std::string>>
319
326
OSUtil::getFilesWithAccessTime (const std::string &Path) {
320
- std::vector<std::pair<time_t , std::string>> Files;
321
- #if __GNUC__ && __GNUC__ < 8
322
- // Should we worry about this case?
323
- assert (false && " getFilesWithAccessTime is not implemented for GCC < 8" );
324
- #else
325
- for (const auto &entry :
326
- std::filesystem::recursive_directory_iterator (Path)) {
327
- if (entry.is_regular_file ()) {
327
+
328
+ Files.clear ();
329
+
330
+ // Use ftw for posix.
328
331
#if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
329
- struct stat StatBuf;
330
- if (stat (entry.path ().c_str (), &StatBuf) == 0 )
331
- Files.push_back ({StatBuf.st_atime , entry.path ().string ()});
332
- #elif defined(__SYCL_RT_OS_WINDOWS)
333
- WIN32_FILE_ATTRIBUTE_DATA FileData;
334
- if (GetFileAttributesEx (entry.path ().c_str (), GetFileExInfoStandard,
335
- &FileData))
336
- Files.push_back (
337
- {FileData.ftLastAccessTime .dwLowDateTime , entry.path ().string ()});
338
- #endif // __SYCL_RT_OS
339
- }
340
- }
332
+ auto GetFiles = [](const char *Fpath, const struct stat *StatBuf,
333
+ int TypeFlag) {
334
+ if (TypeFlag == FTW_F)
335
+ Files.push_back ({StatBuf->st_atime , std::string (Fpath)});
336
+ return 0 ;
337
+ };
338
+
339
+ if (ftw (Path.c_str (), GetFiles, 1 ) == -1 )
340
+ std::cerr << " Failed to get files with access time: " << Path << std::endl;
341
341
#endif
342
+
342
343
return Files;
343
344
}
344
345
0 commit comments