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
|
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
|
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
-
+
+
+
-
-
+
+
+
-
+
+
+
|
void *pool = objc_autoreleasePoolPush();
[of_stdout writeLine: [entry fileName]];
if (app->_outputLevel >= 1) {
OFString *date = [[entry modificationDate]
localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
OFString *size = [OFString stringWithFormat:
@"%" PRIu64, [entry size]];
OFString *mode = [OFString stringWithFormat:
@"%06o", [entry mode]];
[of_stdout writeFormat:
@"\tSize: %" PRIu64 @" bytes\n"
@"\tMode: %06o\n",
[entry size], [entry mode]];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_size",
@"Size: %[size] bytes",
@"size", size)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_mode",
@"Mode: %[mode]",
@"mode", mode)];
if ([entry owner] != nil)
[of_stdout writeFormat: @"\tOwner: %@\n",
[entry owner]];
if ([entry group] != nil)
[of_stdout writeFormat: @"\tGroup: %@\n",
[entry group]];
[of_stdout writeFormat: @"\tModification date: %@\n",
date];
if ([entry owner] != nil) {
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_owner",
@"Owner: %[owner]",
@"owner", [entry owner])];
}
if ([entry group] != nil) {
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_group",
@"Group: %[group]",
@"group", [entry group])];
}
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_modification_date",
@"Modification date: %[date]",
@"date", date)];
}
if (app->_outputLevel >= 2) {
[of_stdout writeString: @"\t"];
switch ([entry type]) {
case OF_TAR_ARCHIVE_ENTRY_TYPE_FILE:
[of_stdout writeLine: @"\tType: Normal file"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_normal",
@"Type: Normal file")];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_LINK:
[of_stdout writeLine: @"\tType: Hard link"];
[of_stdout writeFormat:
@"\tTarget file name: %@\n",
[entry targetFileName]];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_hardlink",
@"Type: Hard link")];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_link_target",
@"Target file name: %[target]",
@"target", [entry targetFileName])];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK:
[of_stdout writeLine: @"\tType: Symbolic link"];
[of_stdout writeFormat:
@"\tTarget file name: %@\n",
[entry targetFileName]];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_symlink",
@"Type: Symbolic link")];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_link_target",
@"Target file name: %[target]",
@"target", [entry targetFileName])];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_CHARACTER_DEVICE:
[of_stdout writeLine:
@"\tType: Character device"];
[of_stdout writeFormat: @"\tDevice major: %d\n"
@"\tDevice minor: %d\n",
[entry deviceMajor],
[entry deviceMinor]];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_CHARACTER_DEVICE: {
OFString *majorString = [OFString
stringWithFormat: @"%d",
[entry deviceMajor]];
OFString *minorString = [OFString
stringWithFormat: @"%d",
[entry deviceMinor]];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_character_device",
@"Type: Character device")];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_device_major",
@"Device major: %[major]",
@"major", majorString)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_device_minor",
@"Device minor: %[minor]",
@"minor", minorString)];
break;
}
case OF_TAR_ARCHIVE_ENTRY_TYPE_BLOCK_DEVICE: {
OFString *majorString = [OFString
stringWithFormat: @"%d",
[entry deviceMajor]];
OFString *minorString = [OFString
stringWithFormat: @"%d",
[entry deviceMinor]];
case OF_TAR_ARCHIVE_ENTRY_TYPE_BLOCK_DEVICE:
[of_stdout writeLine:
@"\tType: Block device"];
[of_stdout writeFormat: @"\tDevice major: %d\n"
@"\tDevice minor: %d\n",
[entry deviceMajor],
[entry deviceMinor]];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_block_device",
@"Type: Block device")];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_device_major",
@"Device major: %[major]",
@"major", majorString)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_device_minor",
@"Device minor: %[minor]",
@"minor", minorString)];
break;
}
case OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY:
[of_stdout writeLine: @"\tType: Directory"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_directory",
@"Type: Directory")];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_FIFO:
[of_stdout writeLine: @"\tType: FIFO"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_fifo",
@"Type: FIFO")];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_CONTIGUOUS_FILE:
[of_stdout writeLine:
@"\tType: Contiguous file"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_contiguous_file",
@"Type: Contiguous file")];
break;
default:
[of_stdout writeLine: @"\tType: Unknown"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_unknown",
@"Type: Unknown")];
break;
}
}
objc_autoreleasePoolPop(pool);
}
}
|
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
|
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
|
-
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
-
+
+
-
-
+
+
+
+
+
+
+
|
int8_t percent = -1, newPercent;
if (!all && ![files containsObject: fileName])
continue;
if ([entry type] != OF_TAR_ARCHIVE_ENTRY_TYPE_FILE) {
if (app->_outputLevel >= 0)
[of_stdout writeFormat: @"Skipping %@...\n",
fileName];
[of_stdout writeLine: OF_LOCALIZED(
@"skipping_file",
@"Skipping %[file]...",
@"file", fileName)];
continue;
}
[missing removeObject: fileName];
#if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
if ([outFileName hasPrefix: @"/"]) {
#else
if ([outFileName hasPrefix: @"/"] ||
[outFileName containsString: @":"]) {
#endif
[of_stderr writeLine: OF_LOCALIZED(
@"refusing_to_extract_file",
[of_stderr writeFormat: @"Refusing to extract %@!\n",
fileName];
@"Refusing to extract %[file]!",
@"file", fileName)];
app->_exitStatus = 1;
goto outer_loop_end;
}
pathComponents = [outFileName pathComponents];
for (OFString *component in pathComponents) {
if ([component isEqual: OF_PATH_PARENT_DIRECTORY]) {
[of_stderr writeFormat:
@"Refusing to extract %@!\n", fileName];
[of_stderr writeLine: OF_LOCALIZED(
@"refusing_to_extract_file",
@"Refusing to extract %[file]!",
@"file", fileName)];
app->_exitStatus = 1;
goto outer_loop_end;
}
}
outFileName = [OFString pathWithComponents: pathComponents];
if (app->_outputLevel >= 0)
[of_stdout writeString: OF_LOCALIZED(@"extracting_file",
[of_stdout writeFormat: @"Extracting %@...", fileName];
@"Extracting %[file]...",
@"file", fileName)];
if ([fileName hasSuffix: @"/"]) {
[fileManager createDirectoryAtPath: outFileName
createParents: true];
setPermissions(outFileName, entry);
if (app->_outputLevel >= 0)
[of_stdout writeLine: @" done"];
if (app->_outputLevel >= 0) {
[of_stdout writeString: @"\r"];
[of_stdout writeLine: OF_LOCALIZED(
@"extracting_file_done",
@"Extracting %[file]... done",
@"file", fileName)];
}
goto outer_loop_end;
}
directory = [outFileName stringByDeletingLastPathComponent];
if (![fileManager directoryExistsAtPath: directory])
[fileManager createDirectoryAtPath: directory
|
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
|
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
+
|
}
written += length;
newPercent = (written == size
? 100 : (int8_t)(written * 100 / size));
if (app->_outputLevel >= 0 && percent != newPercent) {
OFString *percentString;
percent = newPercent;
percentString = [OFString stringWithFormat:
@"%3u", percent];
[of_stdout writeFormat:
@"\rExtracting %@... %3u%%",
fileName, percent];
[of_stdout writeString: @"\r"];
[of_stdout writeString: OF_LOCALIZED(
@"extracting_file_percent",
@"Extracting %[file]... %[percent]%",
@"file", fileName,
@"percent", percentString)];
}
}
if (app->_outputLevel >= 0)
[of_stdout writeFormat: @"\rExtracting %@... done\n",
fileName];
if (app->_outputLevel >= 0) {
[of_stdout writeString: @"\r"];
[of_stdout writeLine: OF_LOCALIZED(
@"extracting_file_done",
@"Extracting %[file]... done",
@"file", fileName)];
}
outer_loop_end:
objc_autoreleasePoolPop(pool);
}
if ([missing count] > 0) {
for (OFString *file in missing)
[of_stderr writeFormat:
@"File %@ is not in the archive!\n", file];
[of_stderr writeLine: OF_LOCALIZED(
@"file_not_in_archive",
@"File %[file] is not in the archive!",
@"file", file)];
app->_exitStatus = 1;
}
}
- (void)printFiles: (OFArray OF_GENERIC(OFString*)*)files_
{
OFMutableSet *files;
OFTarArchiveEntry *entry;
if ([files_ count] < 1) {
[of_stderr writeLine: OF_LOCALIZED(@"print_no_file_specified",
[of_stderr writeLine: @"Need one or more files to print!"];
@"Need one or more files to print!")];
app->_exitStatus = 1;
return;
}
files = [OFMutableSet setWithArray: files_];
while ((entry = [_archive nextEntry]) != nil) {
|