| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2022, the SerenityOS developers. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-12 05:40:29 -07:00
										 |  |  | #include <AK/Time.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  | #include <LibCore/DirIterator.h>
 | 
					
						
							| 
									
										
										
										
											2025-05-30 10:50:55 +02:00
										 |  |  | #include <LibFileSystem/FileSystem.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(AK_OS_WINDOWS)
 | 
					
						
							|  |  |  | #    include <fcntl.h>
 | 
					
						
							|  |  |  | #    include <sys/stat.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Test { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline double get_time_in_ms() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-02-12 05:40:29 -07:00
										 |  |  |     auto now = UnixDateTime::now(); | 
					
						
							|  |  |  |     return static_cast<double>(now.milliseconds_since_epoch()); | 
					
						
							| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename Callback> | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | inline void iterate_directory_recursively(ByteString const& directory_path, Callback callback) | 
					
						
							| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (directory_iterator.has_next()) { | 
					
						
							|  |  |  |         auto name = directory_iterator.next_path(); | 
					
						
							| 
									
										
										
										
											2025-05-30 10:50:55 +02:00
										 |  |  |         auto full_path = LexicalPath::join(directory_path, name).string(); | 
					
						
							|  |  |  | #if defined(AK_OS_WINDOWS)
 | 
					
						
							|  |  |  |         bool is_directory = FileSystem::is_directory(full_path); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  |         struct stat st = {}; | 
					
						
							|  |  |  |         if (fstatat(directory_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW) < 0) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         bool is_directory = S_ISDIR(st.st_mode); | 
					
						
							| 
									
										
										
										
											2025-05-30 10:50:55 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-09-09 23:52:21 +02:00
										 |  |  |         if (is_directory && name != "/Fixtures"sv) { | 
					
						
							|  |  |  |             iterate_directory_recursively(full_path, callback); | 
					
						
							|  |  |  |         } else if (!is_directory) { | 
					
						
							|  |  |  |             callback(full_path); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |