TarEntry.h
1 /* Copyright (C) 2008 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef PT_SYSTEM_TAR_ENTRY_H
30 #define PT_SYSTEM_TAR_ENTRY_H
31 
32 #include <Pt/System/Api.h>
33 #include <Pt/System/FileInfo.h>
34 #include <Pt/System/Path.h>
35 #include <Pt/DateTime.h>
36 
37 #include <cstddef>
38 
39 namespace Pt {
40 
41 namespace System {
42 
61 class TarEntry
62 {
63  public:
66  enum Type
67  {
68  Invalid = 0,
69  File = 1,
70  Directory = 2,
71  Link = 3,
72  Hardlink = 4
73  };
74 
77  TarEntry() = default;
78 
81  TarEntry(TarEntry&&) = default;
82 
85  TarEntry& operator=(TarEntry&&) = default;
86 
89  ~TarEntry() = default;
90 
93  void clear()
94  { *this = TarEntry(); }
95 
101  bool isEnd() const
102  { return _avail == _remaining; }
103 
106  const Pt::System::Path& path() const
107  { return _path; }
108 
111  std::size_t size() const
112  { return _size; }
113 
116  std::size_t remaining() const
117  { return _remaining; }
118 
121  std::size_t avail() const
122  { return _avail; }
123 
129  const char* data() const
130  { return _data; }
131 
134  Type type() const
135  { return _type; }
136 
140  { return _linkTarget; }
141 
145  { return _permissions; }
146 
149  const Pt::DateTime& mtime() const
150  { return _mtime; }
151 
155  { _path = path; }
156 
159  void setSize(std::size_t size)
160  { _size = size; }
161 
164  void setRemaining(std::size_t remaining)
165  { _remaining = remaining; }
166 
169  void setData(const char* data, std::size_t avail)
170  { _data = data; _avail = avail; }
171 
175  { _type = type; }
176 
179  void setLinkTarget(const Pt::System::Path& target)
180  { _linkTarget = target; }
181 
185  { _permissions = p; }
186 
190  { _mtime = mtime; }
191 
192  private:
193  TarEntry(const TarEntry&) = delete;
194 
195  TarEntry& operator=(const TarEntry&) = delete;
196 
197  private:
198  Pt::System::Path _path;
199  std::size_t _size = 0;
200  std::size_t _remaining = 0;
201  std::size_t _avail = 0;
202  const char* _data = 0;
203  Type _type = Invalid;
204  Pt::System::Path _linkTarget;
205  Pt::System::FileInfo::Perms _permissions;
206  Pt::DateTime _mtime;
207 };
208 
209 } // namespace System
210 
211 } // namespace Pt
212 
213 #endif // include guard
Core module.
Definition: Allocator.h:33
void setPermissions(Pt::System::FileInfo::Perms p)
Sets the POSIX permission bits.
Definition: TarEntry.h:184
void setSize(std::size_t size)
Sets the total content size in bytes.
Definition: TarEntry.h:159
const char * data() const
Pointer to the current content chunk of avail() bytes.
Definition: TarEntry.h:129
@ Directory
Directory.
Definition: TarEntry.h:70
void setRemaining(std::size_t remaining)
Sets the number of content bytes not yet delivered.
Definition: TarEntry.h:164
TarEntry()=default
Default constructor.
const Pt::DateTime & mtime() const
Last modification time of this entry.
Definition: TarEntry.h:149
Pt::System::FileInfo::Perms permissions() const
POSIX permission bits for this entry.
Definition: TarEntry.h:144
Perms
File permission flags.
Definition: FileInfo.h:117
Type
Entry type in the tar archive.
Definition: TarEntry.h:67
void setPath(const Pt::System::Path &path)
Sets the archive path.
Definition: TarEntry.h:154
bool isEnd() const
Returns true when the entire content has been delivered.
Definition: TarEntry.h:101
void setData(const char *data, std::size_t avail)
Sets the current data chunk pointer and the number of available bytes.
Definition: TarEntry.h:169
void setMtime(const Pt::DateTime &mtime)
Sets the modification time.
Definition: TarEntry.h:189
const Pt::System::Path & linkTarget() const
Target path for symbolic and hard links (UTF-8 encoded).
Definition: TarEntry.h:139
void setType(Type type)
Sets the entry type.
Definition: TarEntry.h:174
Represents a path in the file-system.
Definition: Path.h:48
const Pt::System::Path & path() const
Archive path of this entry (UTF-8 encoded).
Definition: TarEntry.h:106
@ Link
Symbolic link.
Definition: TarEntry.h:71
TarEntry & operator=(TarEntry &&)=default
Move assignment.
void setLinkTarget(const Pt::System::Path &target)
Sets the link target path.
Definition: TarEntry.h:179
TarEntry(TarEntry &&)=default
Move constructor.
std::size_t avail() const
Number of bytes readable at the current data() pointer.
Definition: TarEntry.h:121
Type type() const
Type of this archive entry (file, directory, link, or hard link).
Definition: TarEntry.h:134
std::size_t size() const
Total content size in bytes as stored in the archive header.
Definition: TarEntry.h:111
@ Invalid
Not yet set.
Definition: TarEntry.h:68
@ File
Regular file.
Definition: TarEntry.h:69
~TarEntry()=default
Destructor.
void clear()
Resets all fields to their default values.
Definition: TarEntry.h:93
@ Hardlink
Hard link.
Definition: TarEntry.h:72
Represents a single entry returned by TarReader.
Definition: TarEntry.h:62
Combined Date and Time value.
Definition: DateTime.h:66
std::size_t remaining() const
Content bytes not yet delivered by TarReader::advance().
Definition: TarEntry.h:116