TarEntry.h
1/* Copyright (C) 2008 Marc Boris Duerner
2 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
3*/
4
5#ifndef PT_SYSTEM_TAR_ENTRY_H
6#define PT_SYSTEM_TAR_ENTRY_H
7
8#include <Pt/System/Api.h>
9#include <Pt/System/FileInfo.h>
10#include <Pt/System/Path.h>
11#include <Pt/DateTime.h>
12#include <Pt/String.h>
13#include <Pt/Types.h>
14
15#include <cstddef>
16
17namespace Pt {
18
19namespace System {
20
72{
73 public:
76 enum Type
77 {
78 Invalid = 0,
79 File = 1,
81 Link = 3,
83 };
84
90 static const Pt::uint32_t NoId = static_cast<Pt::uint32_t>(-1);
91
92 public:
95 TarEntry() = default;
96
99 TarEntry(TarEntry&&) = default;
100
104
107 ~TarEntry() = default;
108
111 void clear()
112 { *this = TarEntry(); }
113
121 bool isEnd() const
122 { return _avail == _remaining; }
123
126 const Pt::System::Path& path() const
127 { return _path; }
128
131 std::size_t size() const
132 { return _size; }
133
138 std::size_t avail() const
139 { return _avail; }
140
147 const char* data() const
148 { return _data; }
149
152 Type type() const
153 { return _type; }
154
160 { return _linkTarget; }
161
168 { return _permissions; }
169
176 const Pt::DateTime& mtime() const
177 { return _mtime; }
178
185 { return _ownerId; }
186
192 const Pt::String& ownerName() const
193 { return _ownerName; }
194
201 { return _groupId; }
202
208 const Pt::String& groupName() const
209 { return _groupName; }
210
214 { _path = path; }
215
221 void setSize(std::size_t size)
222 { _size = size; }
223
227 { _type = type; }
228
231 void setLinkTarget(const Pt::System::Path& target)
232 { _linkTarget = target; }
233
238
242 { _mtime = mtime; }
243
249 { _ownerId = id; }
250
256 void setOwnerName(const Pt::String& name)
257 { _ownerName = name; }
258
264 { _groupId = id; }
265
271 void setGroupName(const Pt::String& name)
272 { _groupName = name; }
273
280 void setContent(const char* data, std::size_t avail, std::size_t remaining)
281 {
282 _data = data;
283 _avail = avail;
284 _remaining = remaining;
285 }
286
287 private:
288 TarEntry(const TarEntry&) = delete;
289
290 TarEntry& operator=(const TarEntry&) = delete;
291
292 private:
293 Pt::System::Path _path;
294 std::size_t _size = 0;
295 std::size_t _remaining = 0;
296 std::size_t _avail = 0;
297 const char* _data = 0;
298 Type _type = Invalid;
299 Pt::System::Path _linkTarget;
301 Pt::DateTime _mtime;
302 Pt::uint32_t _ownerId = NoId;
303 Pt::String _ownerName;
304 Pt::uint32_t _groupId = NoId;
305 Pt::String _groupName;
306};
307
308} // namespace System
309
310} // namespace Pt
311
312#endif // PT_SYSTEM_TAR_ENTRY_H
Combined Date and Time value.
Definition DateTime.h:66
Unicode capable basic_string.
Definition Api-String.h:67
Perms
File permission flags.
Definition FileInfo.h:117
@ NoPerms
No permissions.
Definition FileInfo.h:118
Represents a path in the file-system.
Definition Path.h:48
TarEntry & operator=(TarEntry &&)=default
Move assignment.
void setPath(const Pt::System::Path &path)
Sets the archive path.
Definition TarEntry.h:213
Type
Kind of archive member.
Definition TarEntry.h:77
@ Directory
Directory.
Definition TarEntry.h:80
@ File
Regular file.
Definition TarEntry.h:79
@ Link
Symbolic link.
Definition TarEntry.h:81
@ Hardlink
Hard link.
Definition TarEntry.h:82
@ Invalid
Not set.
Definition TarEntry.h:78
const Pt::String & ownerName() const
Returns the owner name.
Definition TarEntry.h:192
void setPermissions(Pt::System::FileInfo::Perms permissions)
Sets the POSIX permission bits.
Definition TarEntry.h:236
void setOwnerName(const Pt::String &name)
Sets the owner name.
Definition TarEntry.h:256
const Pt::System::Path & path() const
Returns the archive path.
Definition TarEntry.h:126
void setSize(std::size_t size)
Sets the content length declared in the header.
Definition TarEntry.h:221
const Pt::String & groupName() const
Returns the group name.
Definition TarEntry.h:208
void setType(Type type)
Sets the member kind.
Definition TarEntry.h:226
Pt::uint32_t ownerId() const
Returns the numeric owner id.
Definition TarEntry.h:184
const Pt::System::Path & linkTarget() const
Returns the target of a symbolic link or a hard link.
Definition TarEntry.h:159
void setOwnerId(Pt::uint32_t id)
Sets the numeric owner id.
Definition TarEntry.h:248
void setGroupId(Pt::uint32_t id)
Sets the numeric group id.
Definition TarEntry.h:263
void setLinkTarget(const Pt::System::Path &target)
Sets the target of a symbolic link or a hard link.
Definition TarEntry.h:231
void setGroupName(const Pt::String &name)
Sets the group name.
Definition TarEntry.h:271
Pt::System::FileInfo::Perms permissions() const
Returns the POSIX permission bits.
Definition TarEntry.h:167
const char * data() const
Returns the current content chunk of avail() bytes.
Definition TarEntry.h:147
Pt::uint32_t groupId() const
Returns the numeric group id.
Definition TarEntry.h:200
void setMtime(const Pt::DateTime &mtime)
Sets the modification time in UTC.
Definition TarEntry.h:241
const Pt::DateTime & mtime() const
Returns the modification time in UTC.
Definition TarEntry.h:176
TarEntry()=default
Creates an entry with no metadata and an empty content window.
void clear()
Resets every field to the default-constructed state.
Definition TarEntry.h:111
TarEntry(TarEntry &&)=default
Move constructor.
bool isEnd() const
Returns true when every content byte has been delivered.
Definition TarEntry.h:121
std::size_t avail() const
Returns the number of bytes readable at data().
Definition TarEntry.h:138
std::size_t size() const
Returns the content length declared in the archive header.
Definition TarEntry.h:131
Type type() const
Returns the member kind.
Definition TarEntry.h:152
~TarEntry()=default
Destructor.
static const Pt::uint32_t NoId
Id value meaning that no numeric id is set.
Definition TarEntry.h:90
uint_type uint32_t
Unsigned 32-bit integer type.
Definition Api-Types.h:52
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33