ObjFW  Check-in [7683a12e79]

Overview
Comment:ofarc: Propagate quarantine xattr when extracting
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7683a12e79df3ffaaa20ef84384d5454d13199fc54726f1c20fb05475a7bdf59
User & Date: js on 2024-03-17 11:55:40
Other Links: manifest | tags
References
2024-03-17
11:58 Fixed ticket [9cc9214217]: ofarc: Propagate the quarantine extended attribute when extracting plus 5 other changes artifact: 672d7f6692 user: js
Context
2024-03-17
12:31
Fix compilation with old Apple GCC check-in: a98ef6d8dd user: js tags: trunk
11:55
ofarc: Propagate quarantine xattr when extracting check-in: 7683a12e79 user: js tags: trunk
09:41
OFFileManagerTests: Add tests for xattr check-in: 23b9666b71 user: js tags: trunk
Changes

Modified utils/ofarc/GZIPArchive.m from [27c819e003] to [0d21396655].

39
40
41
42
43
44
45


46
47
48
49
50
51
52
	OFFileAttributes destinationAttributes = [OFDictionary
	    dictionaryWithObject: [attributes objectForKey: key]
			  forKey: key];

	[fileManager setAttributes: destinationAttributes
		      ofItemAtPath: destination];
#endif


}

static void
setModificationDate(OFString *path, OFGZIPStream *stream)
{
	OFDate *modificationDate = stream.modificationDate;
	OFFileAttributes attributes;







>
>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	OFFileAttributes destinationAttributes = [OFDictionary
	    dictionaryWithObject: [attributes objectForKey: key]
			  forKey: key];

	[fileManager setAttributes: destinationAttributes
		      ofItemAtPath: destination];
#endif

	[app quarantineFile: destination];
}

static void
setModificationDate(OFString *path, OFGZIPStream *stream)
{
	OFDate *modificationDate = stream.modificationDate;
	OFFileAttributes attributes;

Modified utils/ofarc/LHAArchive.m from [e916d4fb21] to [7235b04681].

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

static void
setPermissions(OFString *path, OFLHAArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	OFNumber *POSIXPermissions = entry.POSIXPermissions;

	if (POSIXPermissions == nil)
		return;

	POSIXPermissions = [OFNumber numberWithUnsignedShort:
	    POSIXPermissions.unsignedShortValue & 0777];

	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: POSIXPermissions
			  forKey: OFFilePOSIXPermissions];

	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];

#endif


}

static void
setModificationDate(OFString *path, OFLHAArchiveEntry *entry)
{
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: entry.modificationDate







|
|

|
|
<
|
|
|

|
|
>

>
>







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

static void
setPermissions(OFString *path, OFLHAArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	OFNumber *POSIXPermissions = entry.POSIXPermissions;

	if (POSIXPermissions != nil) {
		OFFileAttributes attributes;

		POSIXPermissions = [OFNumber numberWithUnsignedShort:
		    POSIXPermissions.unsignedShortValue & 0777];

		attributes = [OFDictionary
		    dictionaryWithObject: POSIXPermissions
				  forKey: OFFilePOSIXPermissions];

		[[OFFileManager defaultManager] setAttributes: attributes
						 ofItemAtPath: path];
	}
#endif

	[app quarantineFile: path];
}

static void
setModificationDate(OFString *path, OFLHAArchiveEntry *entry)
{
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: entry.modificationDate

Modified utils/ofarc/OFArc.h from [3694789001] to [380463fdf7].

27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
#endif
#ifndef S_IRWXO
# define S_IRWXO 0
#endif

@interface OFArc: OFObject <OFApplicationDelegate>
{

	int8_t _overwrite;
@public
	int8_t _outputLevel;
	int _exitStatus;
}

- (id <Archive>)openArchiveWithIRI: (nullable OFIRI *)IRI
			      type: (OFString *)type
			      mode: (char)mode
			  encoding: (OFStringEncoding)encoding;
- (bool)shouldExtractFile: (OFString *)fileName
	      outFileName: (OFString *)outFileName;
- (ssize_t)copyBlockFromStream: (OFStream *)input
		      toStream: (OFStream *)output
		      fileName: (OFString *)fileName;
- (nullable OFString *)safeLocalPathForPath: (OFString *)path;

@end

OF_ASSUME_NONNULL_END







>
















>



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#endif
#ifndef S_IRWXO
# define S_IRWXO 0
#endif

@interface OFArc: OFObject <OFApplicationDelegate>
{
	OFData *_quarantine;
	int8_t _overwrite;
@public
	int8_t _outputLevel;
	int _exitStatus;
}

- (id <Archive>)openArchiveWithIRI: (nullable OFIRI *)IRI
			      type: (OFString *)type
			      mode: (char)mode
			  encoding: (OFStringEncoding)encoding;
- (bool)shouldExtractFile: (OFString *)fileName
	      outFileName: (OFString *)outFileName;
- (ssize_t)copyBlockFromStream: (OFStream *)input
		      toStream: (OFStream *)output
		      fileName: (OFString *)fileName;
- (nullable OFString *)safeLocalPathForPath: (OFString *)path;
- (void)quarantineFile: (OFString *)path;
@end

OF_ASSUME_NONNULL_END

Modified utils/ofarc/OFArc.m from [1f3c890653] to [865148b0dc].

32
33
34
35
36
37
38

39
40
41
42
43
44
45
#import "GZIPArchive.h"
#import "LHAArchive.h"
#import "TarArchive.h"
#import "ZIPArchive.h"
#import "ZooArchive.h"

#import "OFCreateDirectoryFailedException.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFWriteFailedException.h"







>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#import "GZIPArchive.h"
#import "LHAArchive.h"
#import "TarArchive.h"
#import "ZIPArchive.h"
#import "ZooArchive.h"

#import "OFCreateDirectoryFailedException.h"
#import "OFGetItemAttributesFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFWriteFailedException.h"
471
472
473
474
475
476
477













478
479
480
481
482
483
484
		[OFApplication of_activateSandbox: sandbox];
#endif

		archive = [self openArchiveWithIRI: IRI
					      type: type
					      mode: mode
					  encoding: encoding];














		if (outputDir != nil) {
			OFFileManager *fileManager =
			    [OFFileManager defaultManager];

			if (![fileManager directoryExistsAtPath: outputDir])
				[fileManager createDirectoryAtPath: outputDir







>
>
>
>
>
>
>
>
>
>
>
>
>







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
		[OFApplication of_activateSandbox: sandbox];
#endif

		archive = [self openArchiveWithIRI: IRI
					      type: type
					      mode: mode
					  encoding: encoding];

#ifdef OF_MACOS
		@try {
			OFString *attributeName = @"com.apple.quarantine";

			_quarantine = [[[OFFileManager defaultManager]
			    extendedAttributeDataForName: attributeName
					     ofItemAtIRI: IRI] retain];
		} @catch (OFGetItemAttributesFailedException *e) {
			if (e.errNo != /*ENOATTR*/ 93)
				@throw e;
		}
#endif

		if (outputDir != nil) {
			OFFileManager *fileManager =
			    [OFFileManager defaultManager];

			if (![fileManager directoryExistsAtPath: outputDir])
				[fileManager createDirectoryAtPath: outputDir
812
813
814
815
816
817
818











819

	[path retain];

	objc_autoreleasePoolPop(pool);

	return [path autorelease];
}











@end







>
>
>
>
>
>
>
>
>
>
>

826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844

	[path retain];

	objc_autoreleasePoolPop(pool);

	return [path autorelease];
}

- (void)quarantineFile: (OFString *)path
{
#ifdef OF_MACOS
	if (_quarantine != nil)
		[[OFFileManager defaultManager]
		    setExtendedAttributeData: _quarantine
				     forName: @"com.apple.quarantine"
				ofItemAtPath: path];
#endif
}
@end

Modified utils/ofarc/TarArchive.m from [123c1d43aa] to [f860d45c18].

45
46
47
48
49
50
51


52
53
54
55
56
57
58
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: POSIXPermissions
			  forKey: OFFilePOSIXPermissions];

	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];
#endif


}

static void
setModificationDate(OFString *path, OFTarArchiveEntry *entry)
{
	OFDate *modificationDate = entry.modificationDate;
	OFFileAttributes attributes;







>
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: POSIXPermissions
			  forKey: OFFilePOSIXPermissions];

	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];
#endif

	[app quarantineFile: path];
}

static void
setModificationDate(OFString *path, OFTarArchiveEntry *entry)
{
	OFDate *modificationDate = entry.modificationDate;
	OFFileAttributes attributes;

Modified utils/ofarc/ZIPArchive.m from [f42e8a7cde] to [1e18caa344].

54
55
56
57
58
59
60


61
62
63
64
65
66
67
		    dictionaryWithObject: mode
				  forKey: OFFilePOSIXPermissions];

		[[OFFileManager defaultManager] setAttributes: attributes
						 ofItemAtPath: path];
	}
#endif


}

static void
setModificationDate(OFString *path, OFZIPArchiveEntry *entry)
{
	OFDate *modificationDate = entry.modificationDate;
	OFFileAttributes attributes;







>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
		    dictionaryWithObject: mode
				  forKey: OFFilePOSIXPermissions];

		[[OFFileManager defaultManager] setAttributes: attributes
						 ofItemAtPath: path];
	}
#endif

	[app quarantineFile: path];
}

static void
setModificationDate(OFString *path, OFZIPArchiveEntry *entry)
{
	OFDate *modificationDate = entry.modificationDate;
	OFFileAttributes attributes;

Modified utils/ofarc/ZooArchive.m from [d217739dcd] to [3ba5496ff7].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56


57
58
59
60
61
62
63

static void
setPermissions(OFString *path, OFZooArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	OFNumber *POSIXPermissions = entry.POSIXPermissions;

	if (POSIXPermissions == nil)
		return;

	POSIXPermissions = [OFNumber numberWithUnsignedShort:
	    POSIXPermissions.unsignedShortValue & 0777];

	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: POSIXPermissions
			  forKey: OFFilePOSIXPermissions];

	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];

#endif


}

static void
setModificationDate(OFString *path, OFZooArchiveEntry *entry)
{
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: entry.modificationDate







|
|

|
|
<
|
|
|

|
|
>

>
>







37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

static void
setPermissions(OFString *path, OFZooArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	OFNumber *POSIXPermissions = entry.POSIXPermissions;

	if (POSIXPermissions != nil) {
		OFFileAttributes attributes;

		POSIXPermissions = [OFNumber numberWithUnsignedShort:
		    POSIXPermissions.unsignedShortValue & 0777];

		attributes = [OFDictionary
		    dictionaryWithObject: POSIXPermissions
				  forKey: OFFilePOSIXPermissions];

		[[OFFileManager defaultManager] setAttributes: attributes
						 ofItemAtPath: path];
	}
#endif

	[app quarantineFile: path];
}

static void
setModificationDate(OFString *path, OFZooArchiveEntry *entry)
{
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: entry.modificationDate