ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
finfo.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
9
10#include "ftree.hpp"
11#if ALIB_DEBUG
13#endif
14
15#if !defined (_WIN32)
16# include <pwd.h>
17# include <grp.h>
18#endif
19
20using namespace alib::lang::system;
21namespace alib::files {
22
23void FInfo::SetLinkTarget(FTree& tree, const PathString& target, const PathString& realTarget)
24{
25 EISymLinkFile& ei= *static_cast<EISymLinkFile*>(extendedInfo);
26 auto& pool= tree.Pool;
27
29 // delete old values
30 if( ei.RealTarget.Buffer() != ei.Target.Buffer()
31 && ei.RealTarget.Buffer() != nullptr )
32 ei.RealTarget.Free(pool);
33 ei.Target.Free(pool);
34
35 // allocate target
36 ei.Target.Allocate(pool, target);
37
38 // real target is same?
39 if( realTarget.Equals(target) )
40 ei.RealTarget= ei.Target;
41 else
42 ei.RealTarget.Allocate(pool, realTarget);
43}
44
45//==================================================================================================
46//=== OwnerAndGroupResolver
47//==================================================================================================
48#if defined ( _WIN32) && !DOXYGEN
49 namespace { NString unknown("<Unknown>"); }
50#endif
51
53{
54 #if !defined ( _WIN32)
55 auto key= fInfo.Owner();
56 auto resultPair= ownerCache.Try( key );
57 if( !resultPair.first )
58 {
59 auto* result= getpwuid(key);
60 resultPair.second.Construct( key, NString(result ? result->pw_name : "?"));
61 }
62 return resultPair.second.Mapped();
63 #else
64 (void) fInfo;
65 return unknown;
66 #endif
67}
68
70{
71 #if !defined ( _WIN32)
72 auto key= fInfo.Group();
73 auto resultPair= groupCache.Try( key );
74 if( !resultPair.first )
75 {
76 auto* result= getgrgid(key);
77 resultPair.second.Construct( key, NString(result ? result->gr_name : "?"));
78 }
79 return resultPair.second.Mapped();
80 #else
81 (void) fInfo;
82 return unknown;
83 #endif
84}
85
86} // namespace [alib::files]
87
The entry type which is embedded in each tree node.
Definition finfo.hpp:26
constexpr uint32_t Group() const noexcept
Definition finfo.hpp:424
void SetLinkTarget(FTree &tree, const lang::system::PathString &target, const lang::system::PathString &realTarget)
Definition finfo.cpp:23
ExtendedEntryInfo * extendedInfo
Extended information, depending on the entry type.
Definition finfo.hpp:380
Permissions
Permission flags. Compatible with posix* definition.
Definition finfo.hpp:100
Qualities
Per-entry information about how a node was scanned.
Definition finfo.hpp:134
constexpr uint32_t Owner() const noexcept
Definition finfo.hpp:422
PoolAllocator Pool
Definition ftree.hpp:178
ALIB_API const NString & GetGroupName(const FInfo &fInfo)
Definition finfo.cpp:69
ALIB_API const NString & GetOwnerName(const FInfo &fInfo)
Definition finfo.cpp:52
void Allocate(TAllocator &allocator, const TString< TChar > &copy)
Definition cstring.hpp:423
void Free(TAllocator &allocator) const
Definition cstring.hpp:452
bool Equals(const TString< TChar > &rhs) const
Definition string.hpp:580
constexpr const TChar * Buffer() const
Definition string.hpp:319
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Definition vtable.inl:473
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
This is the reference documentation of sub-namespace system of module ALib BaseCamp.
Definition basecamp.cpp:75
strings::TString< nchar > NString
Type alias in namespace alib.
lang::system::CPathString RealTarget
The resolved real target path.
Definition finfo.hpp:324
lang::system::CPathString Target
Definition finfo.hpp:322