Skip to content

Commit 145e81f

Browse files
committed
More fixes
1 parent 6f151d3 commit 145e81f

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

sycl/include/sycl/detail/os_util.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class __SYCL_EXPORT OSUtil {
101101
getFilesWithAccessTime(const std::string &Path);
102102

103103
static size_t DirSizeVar;
104+
static std::vector<std::pair<time_t, std::string>> Files;
104105
};
105106

106107
} // namespace detail

sycl/source/detail/os_util.cpp

+32-31
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ size_t OSUtil::getDirectorySize(const std::string &Path) {
286286
// Use ftw for Linux and darwin as they support posix.
287287
#if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
288288
auto SumSize = []([[maybe_unused]] const char *Fpath,
289-
const struct stat *StatBuf, [[maybe_unused]] int TypeFlag) {
289+
const struct stat *StatBuf, int TypeFlag) {
290290
if (TypeFlag == FTW_F)
291291
DirSizeVar += StatBuf->st_size;
292292
return 0;
293293
};
294294

295-
if (ftw(Path.c_str(),SumSize, 1) == -1)
295+
if (ftw(Path.c_str(), SumSize, 1) == -1)
296296
std::cerr << "Failed to get directory size: " << Path << std::endl;
297297
#endif
298298

@@ -302,43 +302,44 @@ size_t OSUtil::getDirectorySize(const std::string &Path) {
302302
// Get size of file in bytes.
303303
size_t OSUtil::getFileSize(const std::string &Path) {
304304
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+
314320
return Size;
315321
}
316322

323+
std::vector<std::pair<time_t, std::string>> OSUtil::Files = {};
317324
// Get list of all files in the directory along with its last access time.
318325
std::vector<std::pair<time_t, std::string>>
319326
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.
328331
#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;
341341
#endif
342+
342343
return Files;
343344
}
344345

0 commit comments

Comments
 (0)