ObjFW  Diff

Differences From Artifact [402b43560b]:

To Artifact [f838c45385]:


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







+

-
-
-
+
+
+
+

-










+
+
+
+
-
-
+
+
-







 * file.
 */

#include "config.h"

#include <inttypes.h>

#import "OFApplication.h"
#import "OFDate.h"
#import "OFSet.h"
#import "OFApplication.h"
#import "OFFileManager.h"
#import "OFFileManager.h"
#import "OFLocalization.h"
#import "OFNumber.h"
#import "OFSet.h"
#import "OFStdIOStream.h"
#import "OFLocalization.h"

#import "TarArchive.h"
#import "OFZIP.h"

static OFZIP *app;

static void
setPermissions(OFString *path, OFTarArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	of_file_attributes_t attributes = [OFDictionary
	    dictionaryWithObject: [OFNumber numberWithUInt16: [entry mode]]
			  forKey: of_file_attribute_key_posix_permissions];

	[[OFFileManager defaultManager]
	    changePermissionsOfItemAtPath: path
	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];
			      permissions: [entry mode]];
#endif
}

@implementation TarArchive
+ (void)initialize
{
	if (self == [TarArchive class])
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
506
507
508
509
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







+
+








+
+



-
+
-

-
-
+
+
-


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


-
+

-
+


-
+

-
-
+
+







		    @"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:
		[entry setMode: [attributes filePOSIXPermissions]];
		    [fileManager permissionsOfItemAtPath: fileName]];
#endif
		[entry setSize: [fileManager sizeOfFileAtPath: fileName]];
		[entry setModificationDate:
		[entry setSize: [attributes fileSize]];
		[entry setModificationDate: [attributes fileModificationDate]];
		    [fileManager modificationDateOfItemAtPath: fileName]];

#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
		uint16_t UID, GID;
		OFString *owner, *group;

		[fileManager getUID: &UID
				GID: &GID
		       ofItemAtPath: fileName];
		[fileManager getOwner: &owner
				group: &group
			 ofItemAtPath: fileName];

		[entry setUID: UID];
		[entry setGID: GID];
		[entry setOwner: owner];
		[entry setGroup: group];
		[entry setUID: [attributes filePOSIXUID]];
		[entry setGID: [attributes filePOSIXGID]];
		[entry setOwner: [attributes fileOwner]];
		[entry setGroup: [attributes fileGroup]];
#endif

		if ([fileManager fileExistsAtPath: fileName])
		if ([type isEqual: of_file_type_regular])
			[entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_FILE];
		else if ([fileManager directoryExistsAtPath: fileName]) {
		else if ([type isEqual: of_file_type_directory]) {
			[entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY];
			[entry setSize: 0];
		} else if ([fileManager symbolicLinkExistsAtPath: fileName]) {
		} else if ([type isEqual: of_file_type_symbolic_link]) {
			[entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK];
			[entry setTargetFileName: [fileManager
			    destinationOfSymbolicLinkAtPath: fileName]];
			[entry setTargetFileName:
			    [attributes fileSymbolicLinkDestination]];
			[entry setSize: 0];
		}

		[entry makeImmutable];

		output = [_archive streamForWritingEntry: entry];