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
|
- (void)listFiles
{
OFTarArchiveEntry *entry;
while ((entry = [_archive nextEntry]) != nil) {
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]];
OFString *UID = [OFString stringWithFormat:
@"%u", [entry UID]];
OFString *GID = [OFString stringWithFormat:
@"%u", [entry GID]];
[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)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_uid",
@"UID: %[uid]",
@"uid", UID)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_gid",
@"GID: %[gid]",
@"gid", GID)];
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: OF_LOCALIZED(
@"list_type_normal",
@"Type: Normal file")];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_LINK:
[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: 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: {
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]];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_block_device",
@"Type: Block device")];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_device_major",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
<
|
<
|
<
|
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
|
- (void)listFiles
{
OFTarArchiveEntry *entry;
while ((entry = [_archive nextEntry]) != nil) {
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];
OFString *UID = [OFString stringWithFormat:
@"%u", entry.UID];
OFString *GID = [OFString stringWithFormat:
@"%u", entry.GID];
[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)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_uid",
@"UID: %[uid]",
@"uid", UID)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_gid",
@"GID: %[gid]",
@"gid", GID)];
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: OF_LOCALIZED(
@"list_type_normal",
@"Type: Normal file")];
break;
case OF_TAR_ARCHIVE_ENTRY_TYPE_LINK:
[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: 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: {
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];
[of_stdout writeLine: OF_LOCALIZED(
@"list_type_block_device",
@"Type: Block device")];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_device_major",
|
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
@"file", fileName)];
}
outer_loop_end:
objc_autoreleasePoolPop(pool);
}
if ([missing count] > 0) {
for (OFString *file in missing)
[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",
@"Need one or more files to print!")];
app->_exitStatus = 1;
return;
}
files = [OFMutableSet setWithArray: files_];
while ((entry = [_archive nextEntry]) != nil) {
OFString *fileName = [entry fileName];
OFStream *stream;
if (![files containsObject: fileName])
continue;
stream = [_archive streamForReadingCurrentEntry];
while (![stream isAtEndOfStream]) {
ssize_t length = [app copyBlockFromStream: stream
toStream: of_stdout
fileName: fileName];
if (length < 0) {
app->_exitStatus = 1;
return;
}
}
[files removeObject: fileName];
[stream close];
if ([files count] == 0)
break;
}
for (OFString *file in files) {
[of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive",
@"File %[file] is not in the archive!",
@"file", file)];
app->_exitStatus = 1;
}
}
- (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files
{
OFFileManager *fileManager = [OFFileManager defaultManager];
if ([files count] < 1) {
[of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified",
@"Need one or more files to add!")];
app->_exitStatus = 1;
return;
}
for (OFString *fileName in files) {
void *pool = objc_autoreleasePoolPush();
of_file_attributes_t attributes;
of_file_type_t type;
OFMutableTarArchiveEntry *entry;
OFStream *output;
if (app->_outputLevel >= 0)
[of_stdout writeString: OF_LOCALIZED(@"adding_file",
@"Adding %[file]...",
@"file", fileName)];
attributes = [fileManager attributesOfItemAtPath: fileName];
type = [attributes fileType];
entry = [OFMutableTarArchiveEntry entryWithFileName: fileName];
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
[entry setMode: [attributes filePOSIXPermissions]];
#endif
[entry setSize: [attributes fileSize]];
[entry setModificationDate: [attributes fileModificationDate]];
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
[entry setUID: [attributes filePOSIXUID]];
[entry setGID: [attributes filePOSIXGID]];
[entry setOwner: [attributes fileOwner]];
[entry setGroup: [attributes fileGroup]];
#endif
if ([type isEqual: of_file_type_regular])
[entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_FILE];
else if ([type isEqual: of_file_type_directory]) {
[entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY];
[entry setSize: 0];
} else if ([type isEqual: of_file_type_symbolic_link]) {
[entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK];
[entry setTargetFileName:
[attributes fileSymbolicLinkDestination]];
[entry setSize: 0];
}
[entry makeImmutable];
output = [_archive streamForWritingEntry: entry];
if ([entry type] == OF_TAR_ARCHIVE_ENTRY_TYPE_FILE) {
uint64_t written = 0, size = [entry size];
int8_t percent = -1, newPercent;
OFFile *input = [OFFile fileWithPath: fileName
mode: @"r"];
while (![input isAtEndOfStream]) {
ssize_t length = [app
copyBlockFromStream: input
toStream: output
fileName: fileName];
if (length < 0) {
app->_exitStatus = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
@"file", fileName)];
}
outer_loop_end:
objc_autoreleasePoolPop(pool);
}
if (missing.count > 0) {
for (OFString *file in missing)
[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",
@"Need one or more files to print!")];
app->_exitStatus = 1;
return;
}
files = [OFMutableSet setWithArray: files_];
while ((entry = [_archive nextEntry]) != nil) {
OFString *fileName = entry.fileName;
OFStream *stream;
if (![files containsObject: fileName])
continue;
stream = [_archive streamForReadingCurrentEntry];
while (!stream.atEndOfStream) {
ssize_t length = [app copyBlockFromStream: stream
toStream: of_stdout
fileName: fileName];
if (length < 0) {
app->_exitStatus = 1;
return;
}
}
[files removeObject: fileName];
[stream close];
if (files.count == 0)
break;
}
for (OFString *file in files) {
[of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive",
@"File %[file] is not in the archive!",
@"file", file)];
app->_exitStatus = 1;
}
}
- (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files
{
OFFileManager *fileManager = [OFFileManager defaultManager];
if (files.count < 1) {
[of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified",
@"Need one or more files to add!")];
app->_exitStatus = 1;
return;
}
for (OFString *fileName in files) {
void *pool = objc_autoreleasePoolPush();
of_file_attributes_t attributes;
of_file_type_t type;
OFMutableTarArchiveEntry *entry;
OFStream *output;
if (app->_outputLevel >= 0)
[of_stdout writeString: OF_LOCALIZED(@"adding_file",
@"Adding %[file]...",
@"file", fileName)];
attributes = [fileManager attributesOfItemAtPath: fileName];
type = attributes.fileType;
entry = [OFMutableTarArchiveEntry entryWithFileName: fileName];
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
entry.mode = attributes.filePOSIXPermissions;
#endif
entry.size = attributes.fileSize;
entry.modificationDate = attributes.fileModificationDate;
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
entry.UID = attributes.filePOSIXUID;
entry.GID = attributes.filePOSIXGID;
entry.owner = attributes.fileOwner;
entry.group = attributes.fileGroup;
#endif
if ([type isEqual: of_file_type_regular])
entry.type = OF_TAR_ARCHIVE_ENTRY_TYPE_FILE;
else if ([type isEqual: of_file_type_directory]) {
entry.type = OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY;
entry.size = 0;
} else if ([type isEqual: of_file_type_symbolic_link]) {
entry.type = OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK;
entry.targetFileName =
attributes.fileSymbolicLinkDestination;
entry.size = 0;
}
[entry makeImmutable];
output = [_archive streamForWritingEntry: entry];
if (entry.type == OF_TAR_ARCHIVE_ENTRY_TYPE_FILE) {
uint64_t written = 0, size = entry.size;
int8_t percent = -1, newPercent;
OFFile *input = [OFFile fileWithPath: fileName
mode: @"r"];
while (!input.atEndOfStream) {
ssize_t length = [app
copyBlockFromStream: input
toStream: output
fileName: fileName];
if (length < 0) {
app->_exitStatus = 1;
|