LibCore: Use utimensat() in Core::File to preserve nanosecond timestamps
This takes care of two FIXMEs! :^)
This commit is contained in:
parent
a9d55ddf57
commit
376b3c95f7
Notes:
sideshowbarker
2024-07-17 05:02:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/376b3c95f7 Pull-request: https://github.com/SerenityOS/serenity/pull/16147 Reviewed-by: https://github.com/Hendiadyoin1
1 changed files with 22 additions and 11 deletions
|
@ -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 };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue