diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-22 21:07:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-11-24 16:56:27 +0100 |
commit | 376b3c95f7c88a4583ccffcbd3cba2a978a5bc58 (patch) | |
tree | 45c292c0a8555d6b5ff39068b17cc72bde91b294 /Userland/Libraries/LibCore/File.cpp | |
parent | a9d55ddf57321b308f428517f2adf62bf6c47724 (diff) | |
download | serenity-376b3c95f7c88a4583ccffcbd3cba2a978a5bc58.zip |
LibCore: Use utimensat() in Core::File to preserve nanosecond timestamps
This takes care of two FIXMEs! :^)
Diffstat (limited to 'Userland/Libraries/LibCore/File.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/File.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
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 <kling@serenityos.org> + * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #include <AK/LexicalPath.h> +#include <AK/Platform.h> #include <AK/ScopeGuard.h> #include <LibCore/DirIterator.h> #include <LibCore/File.h> @@ -453,11 +454,16 @@ ErrorOr<void, File::CopyError> 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<void, File::CopyError> 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 }; } |