-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patharchive_entry.cpp
258 lines (206 loc) · 6.16 KB
/
archive_entry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
BSD 2-Clause license
Copyright (c) 2014, Domen Vrankar
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_entry.hpp"
#include "archive_exception.hpp"
namespace ns_archive {
entry::entry(archive_entry* entry, ns_reader::entry_buffer& entry_buffer) :
_entry( entry, []( archive_entry* entry ){ /* do nothing as this entry is owned by a reader */ } ),
_stream(&entry_buffer),
_has_stream(true)
{
//
}
entry::entry(std::istream& stream) :
_entry( archive_entry_new(), []( archive_entry* entry ){ archive_entry_free( entry ); } ),
_stream( stream.rdbuf() ),
_has_stream(true)
{
auto* pbuf = _stream.rdbuf();
std::size_t stream_size = pbuf->pubseekoff( 0, _stream.end, _stream.in );
pbuf->pubseekpos( 0, _stream.in );
archive_entry_set_mode( _entry.get(), S_IFREG );
archive_entry_set_size( _entry.get(), stream_size );
}
void entry::clear_entry(std::istream& stream)
{
archive_entry_clear( _entry.get() );
_stream.rdbuf( stream.rdbuf() );
_has_stream = true;
auto* pbuf = _stream.rdbuf();
std::size_t stream_size = pbuf->pubseekoff( 0, _stream.end, _stream.in );
pbuf->pubseekpos( 0, _stream.in );
archive_entry_set_mode( _entry.get(), S_IFREG );
archive_entry_set_size( _entry.get(), stream_size );
}
//-------------------------getters---------------------------//
int64_t entry::get_header_value_gid()
{
return archive_entry_gid(_entry.get());
}
int64_t entry::get_header_value_ino()
{
return archive_entry_ino(_entry.get());
}
int64_t entry::get_header_value_ino64()
{
return archive_entry_ino64(_entry.get());
}
int64_t entry::get_header_value_size()
{
return archive_entry_size(_entry.get());
}
int64_t entry::get_header_value_uid()
{
return archive_entry_uid(_entry.get());
}
mode_t entry::get_header_value_mode()
{
return archive_entry_mode(_entry.get());
}
mode_t entry::get_header_value_perm()
{
return archive_entry_perm(_entry.get());
}
dev_t entry::get_header_value_rdev()
{
return archive_entry_rdev(_entry.get());
}
dev_t entry::get_header_value_rdevmajor()
{
return archive_entry_rdevmajor(_entry.get());
}
dev_t entry::get_header_value_rdevminor()
{
return archive_entry_rdevminor(_entry.get());
}
std::string entry::get_header_value_gname()
{
return archive_entry_gname(_entry.get());
}
std::string entry::get_header_value_hardlink()
{
return archive_entry_hardlink(_entry.get());
}
std::string entry::get_header_value_pathname()
{
return archive_entry_pathname(_entry.get());
}
std::string entry::get_header_value_symlink()
{
return archive_entry_symlink(_entry.get());
}
std::string entry::get_header_value_uname()
{
return archive_entry_uname(_entry.get());
}
unsigned int entry::get_header_value_nlink()
{
return archive_entry_nlink(_entry.get());
}
//-------------------------setters---------------------------//
void entry::set_header_value_gid(int64_t value)
{
archive_entry_set_gid(_entry.get(), value);
}
void entry::set_header_value_ino(int64_t value)
{
archive_entry_set_ino(_entry.get(), value);
}
void entry::set_header_value_ino64(int64_t value)
{
archive_entry_set_ino64(_entry.get(), value);
}
void entry::set_header_value_size(int64_t value)
{
archive_entry_set_size(_entry.get(), value);
}
void entry::set_header_value_uid(int64_t value)
{
archive_entry_set_uid(_entry.get(), value);
}
void entry::set_header_value_mode(mode_t value)
{
archive_entry_set_mode(_entry.get(), value);
}
void entry::set_header_value_perm(mode_t value)
{
archive_entry_set_perm(_entry.get(), value);
}
void entry::set_header_value_rdev(dev_t value)
{
archive_entry_set_rdev(_entry.get(), value);
}
void entry::set_header_value_rdevmajor(dev_t value)
{
archive_entry_set_rdevmajor(_entry.get(), value);
}
void entry::set_header_value_rdevminor(dev_t value)
{
archive_entry_set_rdevminor(_entry.get(), value);
}
void entry::set_header_value_gname(const std::string& value)
{
archive_entry_set_gname(_entry.get(), value.c_str());
}
void entry::set_header_value_hardlink(const std::string& value)
{
archive_entry_set_hardlink(_entry.get(), value.c_str());
}
void entry::set_header_value_link(const std::string& value)
{
archive_entry_set_link(_entry.get(), value.c_str());
}
void entry::set_header_value_pathname(const std::string& value)
{
archive_entry_set_pathname(_entry.get(), value.c_str());
}
void entry::set_header_value_symlink(const std::string& value)
{
archive_entry_set_symlink(_entry.get(), value.c_str());
}
void entry::set_header_value_uname(const std::string& value)
{
archive_entry_set_uname(_entry.get(), value.c_str());
}
void entry::set_header_value_nlink(unsigned int value)
{
archive_entry_set_nlink(_entry.get(), value);
}
void entry::set_header_value_mtime(time_t time, long value)
{
archive_entry_set_mtime(_entry.get(), time, value);
}
archive_entry* entry::get_entry() const
{
return _entry.get();
}
std::istream& entry::get_stream()
{
if(_has_stream)
{
_has_stream = false;
return _stream;
}
throw archive_exception( "Archive entry stream was already read!" );
}
}