ObjFW  Diff

Differences From Artifact [e3da7730a5]:

To Artifact [9618c37951]:


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
10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32







-
-









-







 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#define OF_TAR_ARCHIVE_ENTRY_M

#include "config.h"

#include <inttypes.h>

#import "OFTarArchiveEntry.h"
#import "OFTarArchiveEntry+Private.h"
#import "OFStream.h"
#import "OFDate.h"

#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"

static OFString *
stringFromBuffer(const char *buffer, size_t length)
{
	for (size_t i = 0; i < length; i++)
		if (buffer[i] == '\0')
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
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







-
+
-
-
+
+
-
-
+







-





-
+
-




-
+






+
-
+
+
+







	if (value > max)
		@throw [OFOutOfRangeException exception];

	return value;
}

@implementation OFTarArchiveEntry
@synthesize fileName = _fileName, mode = _mode, size = _size;
+ (instancetype)entryWithFileName: (OFString *)fileName
@synthesize modificationDate = _modificationDate, type = _type;
@synthesize targetFileName = _targetFileName;
{
	return [[[self alloc] initWithFileName: fileName] autorelease];
@synthesize owner = _owner, group = _group;
@synthesize deviceMajor = _deviceMajor, deviceMinor = _deviceMinor;
}

- init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_initWithHeader: (char [512])header
			   stream: (OFStream *)stream
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		OFString *targetFileName;
		_stream = [stream retain];

		_fileName = [stringFromBuffer(header, 100) copy];
		_mode = (uint32_t)octalValueFromBuffer(
		    header + 100, 8, UINT32_MAX);
		_size = _toRead = (uint64_t)octalValueFromBuffer(
		_size = (uint64_t)octalValueFromBuffer(
		    header + 124, 12, UINT64_MAX);
		_modificationDate = [[OFDate alloc]
		    initWithTimeIntervalSince1970:
		    (of_time_interval_t)octalValueFromBuffer(
		    header + 136, 12, UINTMAX_MAX)];
		_type = header[156];

		_targetFileName = [stringFromBuffer(header + 157, 100) copy];
		targetFileName = stringFromBuffer(header + 157, 100);
		if ([targetFileName length] > 0)
			_targetFileName = [targetFileName copy];

		if (_type == '\0')
			_type = OF_TAR_ARCHIVE_ENTRY_TYPE_FILE;

		if (memcmp(header + 257, "ustar\0" "00", 8) == 0) {
			OFString *fileName;

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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-









-
+
-

-
-
-
+
+
+
-
-
-
+
+
+
+
-

+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-

-
+
-
-
-
-
-
+
+
+
+
+


-
+

-
+
-
-
+
-
-
-
-
+
+
+
+
+
+
+

-
+


-
+

-
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
-
-
+
+
+

-
-
-
-
-
+
+
+
+

-
-
+
-
+
+







	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithFileName: (OFString *)fileName
{
	self = [super init];

	@try {
		_fileName = [fileName copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[self close];

	[_fileName release];
	[_modificationDate release];
	[_targetFileName release];
	[_owner release];
	[_group release];

	[super dealloc];
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
- copy
			  length: (size_t)length
{
	size_t ret;

	if (_stream == nil)
	return [self retain];
}

		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
- mutableCopy
{
	OFTarArchiveEntry *copy = [[OFMutableTarArchiveEntry alloc]
	    initWithFileName: _fileName];
		return 0;

	@try {
	if ((uint64_t)length > _toRead)
		length = (size_t)_toRead;

		copy->_mode = _mode;
		copy->_size = _size;
		copy->_modificationDate = [_modificationDate copy];
		copy->_type = _type;
		copy->_targetFileName = [_targetFileName copy];
		copy->_owner = [_owner copy];
		copy->_group = [_group copy];
		copy->_deviceMajor = _deviceMajor;
		copy->_deviceMinor = _deviceMinor;
	} @catch (id e) {
		[copy release];
		@throw e;
	}
	ret = [_stream readIntoBuffer: buffer
			       length: length];

	if (ret == 0)
	return copy;
		_atEndOfStream = true;

	_toRead -= ret;

	return ret;
}

- (OFString *)fileName
{
	return _fileName;
}

- (bool)lowlevelIsAtEndOfStream
- (uint32_t)mode
{
	if (_stream == nil)
	return _mode;
		@throw [OFNotOpenException exceptionWithObject: self];

}
	return _atEndOfStream;
}

- (bool)hasDataInReadBuffer

- (uint64_t)size
{
	return _size;
}

- (OFDate *)modificationDate
{
	return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer]);
	return _modificationDate;
}

- (void)close
- (of_tar_archive_entry_type_t)type
{
	[_stream release];
	_stream = nil;

	return _type;
}
	[super close];
}


- (OFString *)targetFileName
{
- (void)of_skip
{
	char buffer[512];

	while (_toRead >= 512) {
	return _targetFileName;
}

- (OFString *)owner
{
	return _owner;
}

		[_stream readIntoBuffer: buffer
			    exactLength: 512];
- (OFString *)group
		_toRead -= 512;
	}
{
	return _group;
}

	if (_toRead > 0) {
		[_stream readIntoBuffer: buffer
			    exactLength: (size_t)_toRead];
		_toRead = 0;
	}
- (uint32_t)deviceMajor
{
	return _deviceMajor;
}

	if (_size % 512 != 0)
		[_stream readIntoBuffer: buffer
- (uint32_t)deviceMinor
			    exactLength: 512 - ((size_t)_size % 512)];
{
	return _deviceMinor;
}

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	OFString *ret = [OFString stringWithFormat: @"<%@:\n"
	     @"\tFile name = %@\n"