ObjFW  Diff

Differences From Artifact [91a459baa0]:

To Artifact [330cc9ede8]:


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







+
-
+


















-
+

-
+

+
-
+








- (instancetype)of_init
{
	self = [super init];

	@try {
		_type = OFTarArchiveEntryTypeFile;
		_POSIXPermissions =
		_mode = [[OFNumber alloc] initWithUnsignedShort: 0644];
		    [[OFNumber alloc] initWithUnsignedShort: 0644];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)of_initWithHeader: (unsigned char [512])header
			 encoding: (OFStringEncoding)encoding
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFString *targetFileName;

		_fileName = [stringFromBuffer(header, 100, encoding) copy];
		_mode = [[OFNumber alloc] initWithUnsignedLongLong:
		_POSIXPermissions = [[OFNumber alloc] initWithUnsignedLongLong:
		    octalValueFromBuffer(header + 100, 8, ULONG_MAX)];
		_UID = [[OFNumber alloc] initWithUnsignedLongLong:
		_ownerAccountID = [[OFNumber alloc] initWithUnsignedLongLong:
		    octalValueFromBuffer(header + 108, 8, ULONG_MAX)];
		_groupOwnerAccountID = [[OFNumber alloc]
		_GID = [[OFNumber alloc] initWithUnsignedLongLong:
		    initWithUnsignedLongLong:
		    octalValueFromBuffer(header + 116, 8, ULONG_MAX)];
		_uncompressedSize = (unsigned long long)octalValueFromBuffer(
		    header + 124, 12, ULLONG_MAX);
		_compressedSize =
		    _uncompressedSize + (512 - _uncompressedSize % 512);
		_modificationDate = [[OFDate alloc]
		    initWithTimeIntervalSince1970:
127
128
129
130
131
132
133

134

135
136
137


138
139
140
141
142
143
144
129
130
131
132
133
134
135
136

137



138
139
140
141
142
143
144
145
146







+
-
+
-
-
-
+
+








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

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

			_ownerAccountName =
			_owner = [stringFromBuffer(header + 265, 32, encoding)
			    [stringFromBuffer(header + 265, 32, encoding) copy];
			    copy];
			_group = [stringFromBuffer(header + 297, 32, encoding)
			    copy];
			_groupOwnerAccountName = [stringFromBuffer(header + 297,
			    32, encoding) copy];

			_deviceMajor = (unsigned long)octalValueFromBuffer(
			    header + 329, 8, ULONG_MAX);
			_deviceMinor = (unsigned long)octalValueFromBuffer(
			    header + 337, 8, ULONG_MAX);

			prefix = stringFromBuffer(header + 345, 155, encoding);
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
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







-
-
-
+
+
+


-
-
+
+















+
-
+
+





-
-
+
+















-
+

-
+


-
+

-
+


-
+

-
+








	return self;
}

- (void)dealloc
{
	[_fileName release];
	[_mode release];
	[_UID release];
	[_GID release];
	[_POSIXPermissions release];
	[_ownerAccountID release];
	[_groupOwnerAccountID release];
	[_modificationDate release];
	[_targetFileName release];
	[_owner release];
	[_group release];
	[_ownerAccountName release];
	[_groupOwnerAccountName release];

	[super dealloc];
}

- (id)copy
{
	return [self retain];
}

- (id)mutableCopy
{
	OFTarArchiveEntry *copy = [[OFMutableTarArchiveEntry alloc]
	    initWithFileName: _fileName];

	@try {
		copy->_POSIXPermissions = [_POSIXPermissions retain];
		copy->_mode = _mode;
		copy->_ownerAccountID = [_ownerAccountID retain];
		copy->_groupOwnerAccountID = [_groupOwnerAccountID retain];
		copy->_compressedSize = _compressedSize;
		copy->_uncompressedSize = _uncompressedSize;
		copy->_modificationDate = [_modificationDate copy];
		copy->_type = _type;
		copy->_targetFileName = [_targetFileName copy];
		copy->_owner = [_owner copy];
		copy->_group = [_group copy];
		copy->_ownerAccountName = [_ownerAccountName copy];
		copy->_groupOwnerAccountName = [_groupOwnerAccountName copy];
		copy->_deviceMajor = _deviceMajor;
		copy->_deviceMinor = _deviceMinor;
	} @catch (id e) {
		[copy release];
		@throw e;
	}

	return copy;
}

- (OFString *)fileName
{
	return _fileName;
}

- (OFNumber *)mode
- (OFNumber *)POSIXPermissions
{
	return _mode;
	return _POSIXPermissions;
}

- (OFNumber *)UID
- (OFNumber *)ownerAccountID
{
	return _UID;
	return _ownerAccountID;
}

- (OFNumber *)GID
- (OFNumber *)groupOwnerAccountID
{
	return _GID;
	return _groupOwnerAccountID;
}

- (unsigned long long)compressedSize
{
	return _compressedSize;
}

244
245
246
247
248
249
250
251

252
253

254
255
256

257
258

259
260
261
262
263
264
265
266
267
268
269
270
271
272
273






274

275
276
277
278



279
280
281
282
283
284
285


286
287
288
289
290
291





292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310


311
312
313


314
315
316


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
248
249
250
251
252
253
254

255
256

257
258
259

260
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285



286
287
288
289
290
291
292
293


294
295
296
297
298



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320


321
322
323


324
325
326


327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347


348
349
350
351
352
353
354
355
356







-
+

-
+


-
+

-
+















+
+
+
+
+
+
-
+

-
-
-
+
+
+





-
-
+
+



-
-
-
+
+
+
+
+

















-
-
+
+

-
-
+
+

-
-
+
+



















-
-
+
+







}

- (OFString *)targetFileName
{
	return _targetFileName;
}

- (OFString *)owner
- (OFString *)ownerAccountName
{
	return _owner;
	return _ownerAccountName;
}

- (OFString *)group
- (OFString *)groupOwnerAccountName
{
	return _group;
	return _groupOwnerAccountName;
}

- (unsigned long)deviceMajor
{
	return _deviceMajor;
}

- (unsigned long)deviceMinor
{
	return _deviceMinor;
}

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	OFString *POSIXPermissions = nil, *ret;

	if (_POSIXPermissions != nil)
		POSIXPermissions = [OFString stringWithFormat: @"%ho",
		    _POSIXPermissions.unsignedShortValue];

	OFString *ret = [OFString stringWithFormat: @"<%@:\n"
	ret = [OFString stringWithFormat: @"<%@:\n"
	     @"\tFile name = %@\n"
	     @"\tMode = %06o\n"
	     @"\tUID = %u\n"
	     @"\tGID = %u\n"
	     @"\tPOSIX permissions = %@\n"
	     @"\tOwner account ID = %@\n"
	     @"\tGroup owner account ID = %@\n"
	     @"\tCompressed size = %llu\n"
	     @"\tUncompressed size = %llu\n"
	     @"\tModification date = %@\n"
	     @"\tType = %u\n"
	     @"\tTarget file name = %@\n"
	     @"\tOwner = %@\n"
	     @"\tGroup = %@\n"
	     @"\tOwner account name = %@\n"
	     @"\tGroup owner account name = %@\n"
	     @"\tDevice major = %" PRIu32 @"\n"
	     @"\tDevice minor = %" PRIu32 @"\n"
	     @">",
	    self.class, _fileName, _mode, _UID, _GID, _compressedSize,
	    _uncompressedSize, _modificationDate, _type, _targetFileName,
	    _owner, _group, _deviceMajor, _deviceMinor];
	    self.class, _fileName, POSIXPermissions, _ownerAccountID,
	    _groupOwnerAccountID, _compressedSize, _uncompressedSize,
	    _modificationDate, _type, _targetFileName,
	    _ownerAccountName, _groupOwnerAccountName, _deviceMajor,
	    _deviceMinor];

	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (void)of_writeToStream: (OFStream *)stream
		encoding: (OFStringEncoding)encoding
{
	unsigned char buffer[512];
	unsigned long long modificationDate;
	uint16_t checksum = 0;

	stringToBuffer(buffer, _fileName, 100, encoding);
	stringToBuffer(buffer + 100,
	    [OFString stringWithFormat: @"%06" PRIo16 " ", _mode], 8,
	    OFStringEncodingASCII);
	    [OFString stringWithFormat: @"%06o ",
	    _POSIXPermissions.unsignedShortValue], 8, OFStringEncodingASCII);
	stringToBuffer(buffer + 108,
	    [OFString stringWithFormat: @"%06" PRIo16 " ", _UID], 8,
	    OFStringEncodingASCII);
	    [OFString stringWithFormat: @"%06o ",
	    _ownerAccountID.unsignedShortValue], 8, OFStringEncodingASCII);
	stringToBuffer(buffer + 116,
	    [OFString stringWithFormat: @"%06" PRIo16 " ", _GID], 8,
	    OFStringEncodingASCII);
	    [OFString stringWithFormat: @"%06o ",
	    _groupOwnerAccountID.unsignedShortValue], 8, OFStringEncodingASCII);
	stringToBuffer(buffer + 124,
	    [OFString stringWithFormat: @"%011llo ", _uncompressedSize], 12,
	    OFStringEncodingASCII);
	modificationDate = _modificationDate.timeIntervalSince1970;
	stringToBuffer(buffer + 136,
	    [OFString stringWithFormat: @"%011llo", modificationDate],
	    12, OFStringEncodingASCII);

	/*
	 * During checksumming, the checksum field is expected to be set to 8
	 * spaces.
	 */
	memset(buffer + 148, ' ', 8);

	buffer[156] = _type;
	stringToBuffer(buffer + 157, _targetFileName, 100, encoding);

	/* ustar */
	memcpy(buffer + 257, "ustar\0" "00", 8);
	stringToBuffer(buffer + 265, _owner, 32, encoding);
	stringToBuffer(buffer + 297, _group, 32, encoding);
	stringToBuffer(buffer + 265, _ownerAccountName, 32, encoding);
	stringToBuffer(buffer + 297, _groupOwnerAccountName, 32, encoding);
	stringToBuffer(buffer + 329,
	    [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMajor], 8,
	    OFStringEncodingASCII);
	stringToBuffer(buffer + 337,
	    [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMinor], 8,
	    OFStringEncodingASCII);
	memset(buffer + 345, '\0', 155 + 12);