ALib C++ Library
Library Version: 2402 R1
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// #################################################################################################
8
10
11#if ALIB_DEBUG
12# if !defined(HPP_ALIB_LANG_FORMAT_FORMATTER)
14# endif
15#endif
16
17namespace alib::files {
18
19//==================================================================================================
20//=== FInfo::WriteTypeAndAccess
21//==================================================================================================
23{
24 auto type = Type();
25 auto perms= Perms();
26 char typeChar= '?';
28 switch( type )
29 {
30 case Types::REGULAR : typeChar= '-'; break;
31 case Types::DIRECTORY : typeChar= 'd'; break;
32 case Types::SYMBOLIC_LINK : typeChar= 'l'; break;
33 case Types::SYMBOLIC_LINK_DIR: typeChar= 'L'; break;
34 case Types::BLOCK : typeChar= 'b'; break;
35 case Types::CHARACTER : typeChar= 'c'; break;
36 case Types::FIFO : typeChar= 'p'; break;
37 case Types::SOCKET : typeChar= 'S'; break;
38 }
40 target << typeChar
41 << ( (perms & Permissions::OWNER_READ ) == Permissions::OWNER_READ ? 'r' : '-' )
42 << ( (perms & Permissions::OWNER_WRITE ) == Permissions::OWNER_WRITE ? 'w' : '-' )
43 << ( (perms & Permissions::OWNER_EXEC ) == Permissions::OWNER_EXEC ? 'x' : '-' )
44 << ( (perms & Permissions::GROUP_READ ) == Permissions::GROUP_READ ? 'r' : '-' )
45 << ( (perms & Permissions::GROUP_WRITE ) == Permissions::GROUP_WRITE ? 'w' : '-' )
46 << ( (perms & Permissions::GROUP_EXEC ) == Permissions::GROUP_EXEC ? 'x' : '-' )
47 << ( (perms & Permissions::OTHERS_READ ) == Permissions::OTHERS_READ ? 'r' : '-' )
48 << ( (perms & Permissions::OTHERS_WRITE) == Permissions::OTHERS_WRITE ? 'w' : '-' )
49 << ( (perms & Permissions::OTHERS_EXEC ) == Permissions::OTHERS_EXEC ? 'x' : '-' )
50 ;
51 return target;
52}
53
54
55void FInfo::SetLinkTarget(const String& target, const String& realTarget)
56{
57 EISymLinkFile& ei= *static_cast<EISymLinkFile*>(extendedInfo);
58
60 // delete old?
61 if(ei. Target.IsNotNull() && ei.Target.Buffer() != ei.internalBuf )
62 delete[] ei.Target.Buffer();
65 delete[] ei.RealTarget.Buffer();
66
67
68 // copy target to buffer or external memory
69 integer tLen= target.Length();
71 : new character[size_t(tLen+1)];
72 target.CopyTo( tp );
73 tp[tLen]= '\0';
74 ei.Target= CString( tp, tLen );
75
76 // real target is same?
77 if( realTarget.Equals(target) )
78 {
79 ei.RealTarget= ei.Target;
80 return;
81 }
82
83 // copy realTarget to remaining buffer or external memory
84 integer bufStart= (ei.internalBuf == ei.Target.Buffer()) ? tLen + 1
85 : 0;
86 tLen= realTarget.Length();
87 tp= (tLen +1 < EISymLinkFile::InternalBufSize - bufStart) ? ei.internalBuf + bufStart
88 : new character[size_t(tLen+1)];
89 realTarget.CopyTo( tp );
90 tp[tLen]= '\0';
91 ei.RealTarget= CString( tp, tLen );
93}
94
95} // namespace [alib::files]
@ DIRECTORY
Directory/folder.
@ CHARACTER
A character special file.
@ BLOCK
A block special file.
@ SOCKET
A socket file.
@ FIFO
A FIFO (also known as pipe) file.
constexpr Permissions Perms() const noexcept
Definition finfo.hpp:405
ExtendedEntryInfo * extendedInfo
Extended information, depending on the entry type.
Definition finfo.hpp:315
void SetLinkTarget(const String &target, const String &realTarget)
Definition finfo.cpp:55
@ GROUP_READ
< S_IRWXU File owner has read, write, and execute/search permissions Equivalent to owner_read | owner...
@ GROUP_EXEC
< S_IWGRP The file's user group has write permission
@ OTHERS_EXEC
S_IXOTH Other users have execute/search permission.
@ GROUP_WRITE
< S_IRGRP The file's user group has read permission
@ OWNER_EXEC
< S_IWUSR File owner has write permission
@ OWNER_WRITE
< S_IRUSR File owner has read permission
@ OTHERS_READ
< S_IRWXG The file's user group has read, write, and execute/search permissions Equivalent to group_r...
@ OTHERS_WRITE
S_IWOTH Other users have write permission.
constexpr Types Type() const noexcept
Definition finfo.hpp:407
AString & WriteTypeAndAccess(AString &target) const
Definition finfo.cpp:22
constexpr integer Length() const
Definition string.hpp:357
constexpr bool IsNotNull() const
Definition string.hpp:402
integer CopyTo(TChar *dest) const
Definition string.hpp:1974
bool Equals(const TString< TChar > &rhs) const
Definition string.hpp:573
constexpr const TChar * Buffer() const
Definition string.hpp:350
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_WARNINGS_ALLOW_SPARSE_ENUM_SWITCH
Definition alib.hpp:669
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
strings::TCString< character > CString
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286
static constexpr integer InternalBufSize
The defined size of the internal buffer.
Definition finfo.hpp:262
character internalBuf[InternalBufSize]
Definition finfo.hpp:263
CString RealTarget
The resolved real target path.
Definition finfo.hpp:268
CString Target
The target path. This is a zero-terminated CString.
Definition finfo.hpp:267