diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index bcf57891c9..3784265168 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include #include @@ -453,11 +454,16 @@ ErrorOr File::copy_file(String const& dst_path, struct st } if (has_flag(preserve_mode, PreserveMode::Timestamps)) { - // FIXME: Implement utimens() and use it here. - struct utimbuf timbuf; - timbuf.actime = src_stat.st_atime; - timbuf.modtime = src_stat.st_mtime; - if (utime(dst_path.characters(), &timbuf) < 0) + struct timespec times[2] = { +#ifdef AK_OS_MACOS + src_stat.st_atimespec, + src_stat.st_mtimespec, +#else + src_stat.st_atim, + src_stat.st_mtim, +#endif + }; + if (utimensat(AT_FDCWD, dst_path.characters(), times, 0) < 0) return CopyError { errno, false }; } @@ -503,11 +509,16 @@ ErrorOr File::copy_directory(String const& dst_path, Stri } if (has_flag(preserve_mode, PreserveMode::Timestamps)) { - // FIXME: Implement utimens() and use it here. - struct utimbuf timbuf; - timbuf.actime = src_stat.st_atime; - timbuf.modtime = src_stat.st_atime; - if (utime(dst_path.characters(), &timbuf) < 0) + struct timespec times[2] = { +#ifdef AK_OS_MACOS + src_stat.st_atimespec, + src_stat.st_mtimespec, +#else + src_stat.st_atim, + src_stat.st_mtim, +#endif + }; + if (utimensat(AT_FDCWD, dst_path.characters(), times, 0) < 0) return CopyError { errno, false }; }