Path: blob/main/contrib/llvm-project/libcxx/src/filesystem/directory_entry.cpp
35231 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include <__config>9#include <cstdint>10#include <filesystem>11#include <system_error>1213#include "file_descriptor.h"14#include "posix_compat.h"15#include "time_utils.h"1617_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM1819error_code directory_entry::__do_refresh() noexcept {20__data_.__reset();21error_code failure_ec;2223detail::StatT full_st;24file_status st = detail::posix_lstat(__p_, full_st, &failure_ec);25if (!status_known(st)) {26__data_.__reset();27return failure_ec;28}2930if (!filesystem::exists(st) || !filesystem::is_symlink(st)) {31__data_.__cache_type_ = directory_entry::_RefreshNonSymlink;32__data_.__type_ = st.type();33__data_.__non_sym_perms_ = st.permissions();34} else { // we have a symlink35__data_.__sym_perms_ = st.permissions();36// Get the information about the linked entity.37// Ignore errors from stat, since we don't want errors regarding symlink38// resolution to be reported to the user.39error_code ignored_ec;40st = detail::posix_stat(__p_, full_st, &ignored_ec);4142__data_.__type_ = st.type();43__data_.__non_sym_perms_ = st.permissions();4445// If we failed to resolve the link, then only partially populate the46// cache.47if (!status_known(st)) {48__data_.__cache_type_ = directory_entry::_RefreshSymlinkUnresolved;49return error_code{};50}51// Otherwise, we resolved the link, potentially as not existing.52// That's OK.53__data_.__cache_type_ = directory_entry::_RefreshSymlink;54}5556if (filesystem::is_regular_file(st))57__data_.__size_ = static_cast<uintmax_t>(full_st.st_size);5859if (filesystem::exists(st)) {60__data_.__nlink_ = static_cast<uintmax_t>(full_st.st_nlink);6162// Attempt to extract the mtime, and fail if it's not representable using63// file_time_type. For now we ignore the error, as we'll report it when64// the value is actually used.65error_code ignored_ec;66__data_.__write_time_ = detail::__extract_last_write_time(__p_, full_st, &ignored_ec);67}6869return failure_ec;70}7172_LIBCPP_END_NAMESPACE_FILESYSTEM737475