ObjFW  Check-in [264126064b]

Overview
Comment:Add support for ustar
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 264126064b27f0b3249fb8e08cc0c614b743014781556f1f8840b8e8aa964ee3
User & Date: js on 2016-05-29 19:59:32
Other Links: manifest | tags
Context
2016-06-04
18:07
PLATFORMS.md: Increase minimum GCC version to 4.6 check-in: 03867d6f12 user: js tags: trunk
2016-05-29
19:59
Add support for ustar check-in: 264126064b user: js tags: trunk
19:43
OFDeflateStream: Fix -[isAtEndOfStream] check-in: 8e4451aee2 user: js tags: trunk
Changes

Modified src/OFTarArchiveEntry.h from [f1881fc452] to [51116eaca4].

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


51
52
53
54
55
56
57
@class OFDate;

/*!
 * @brief The type of the archive entry.
 */
typedef enum of_tar_archive_entry_type_t {
	/*! Normal file */
	OF_TAR_ARCHIVE_ENTRY_TYPE_FILE	  = '0',
	/*! Hard link */
	OF_TAR_ARCHIVE_ENTRY_TYPE_LINK	  = '1',
	/*! Symbolic link */
	OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK = '2'










} of_tar_archive_entry_type_t;

/*!
 * @class OFTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h
 *
 * @brief A class which represents an entry of a tar archive.
 */
@interface OFTarArchiveEntry: OFStream
{
	OFStream *_stream;
	bool _atEndOfStream;
	OFString *_fileName;
	uint32_t _mode;
	uint64_t _size, _toRead;
	OFDate *_modificationDate;
	of_tar_archive_entry_type_t _type;
	OFString *_targetFileName;


}

/*!
 * The file name of the entry.
 */
@property (readonly, copy) OFString *fileName;








|

|

|
>
>
>
>
>
>
>
>
>
>

















>
>







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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@class OFDate;

/*!
 * @brief The type of the archive entry.
 */
typedef enum of_tar_archive_entry_type_t {
	/*! Normal file */
	OF_TAR_ARCHIVE_ENTRY_TYPE_FILE		   = '0',
	/*! Hard link */
	OF_TAR_ARCHIVE_ENTRY_TYPE_LINK		   = '1',
	/*! Symbolic link */
	OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK	   = '2',
	/*! Character device */
	OF_TAR_ARCHIVE_ENTRY_TYPE_CHARACTER_DEVICE = '3',
	/*! Block device */
	OF_TAR_ARCHIVE_ENTRY_TYPE_BLOCK_DEVICE	   = '4',
	/*! Directory */
	OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY	   = '5',
	/*! FIFO */
	OF_TAR_ARCHIVE_ENTRY_TYPE_FIFO		   = '6',
	/*! Contiguous file */
	OF_TAR_ARCHIVE_ENTRY_TYPE_CONTIGUOUS_FILE  = '7',
} of_tar_archive_entry_type_t;

/*!
 * @class OFTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h
 *
 * @brief A class which represents an entry of a tar archive.
 */
@interface OFTarArchiveEntry: OFStream
{
	OFStream *_stream;
	bool _atEndOfStream;
	OFString *_fileName;
	uint32_t _mode;
	uint64_t _size, _toRead;
	OFDate *_modificationDate;
	of_tar_archive_entry_type_t _type;
	OFString *_targetFileName;
	OFString *_owner, *_group;
	uint32_t _deviceMajor, _deviceMinor;
}

/*!
 * The file name of the entry.
 */
@property (readonly, copy) OFString *fileName;

77
78
79
80
81
82
83




















84
85
86
 */
@property (readonly) of_tar_archive_entry_type_t type;

/*!
 * The file name of the target (for a hard link or symbolic link).
 */
@property (readonly, copy) OFString *targetFileName;




















@end

OF_ASSUME_NONNULL_END







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



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
 */
@property (readonly) of_tar_archive_entry_type_t type;

/*!
 * The file name of the target (for a hard link or symbolic link).
 */
@property (readonly, copy) OFString *targetFileName;

/*!
 * The owner of the file.
 */
@property (readonly, copy) OFString *owner;

/*!
 * The group of the file.
 */
@property (readonly, copy) OFString *group;

/*!
 * The device major (if the file is a device).
 */
@property (readonly) uint32_t deviceMajor;

/*!
 * The device major (if the file is a device).
 */
@property (readonly) uint32_t deviceMinor;
@end

OF_ASSUME_NONNULL_END

Modified src/OFTarArchiveEntry.m from [d10ff12b41] to [eff1f9c576].

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
75
76
77
78
79

















80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95


96
97
98
99
100
101
102
	return value;
}

@implementation OFTarArchiveEntry
@synthesize fileName = _fileName, mode = _mode, size = _size;
@synthesize modificationDate = _modificationDate, type = _type;
@synthesize targetFileName = _targetFileName;



- (instancetype)OF_initWithHeader: (char[512])header
			   stream: (OFStream*)stream
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		_stream = [stream retain];

		_fileName = [stringFromBuffer(header, 100) copy];
		_mode = (uint32_t)octalValueFromBuffer(
		    header + 100, 8, UINT32_MAX);
		_size = _toRead = (size_t)octalValueFromBuffer(
		    header + 124, 12, UINT64_MAX);
		_modificationDate = [[OFDate alloc]
		    initWithTimeIntervalSince1970:
		    (of_time_interval_t)octalValueFromBuffer(
		    header + 136, 12, UINTMAX_MAX)];
		_type = header[156];
		_targetFileName = [stringFromBuffer(header + 157, 100) copy];

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


















		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_stream release];
	[_fileName release];
	[_modificationDate release];
	[_targetFileName release];



	[super dealloc];
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{







>
>














|










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
















>
>







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
75
76
77
78
79
80
81
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
122
123
	return value;
}

@implementation OFTarArchiveEntry
@synthesize fileName = _fileName, mode = _mode, size = _size;
@synthesize modificationDate = _modificationDate, type = _type;
@synthesize targetFileName = _targetFileName;
@synthesize owner = _owner, group = _group;
@synthesize deviceMajor = _deviceMajor, deviceMinor = _deviceMinor;

- (instancetype)OF_initWithHeader: (char[512])header
			   stream: (OFStream*)stream
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		_stream = [stream retain];

		_fileName = [stringFromBuffer(header, 100) copy];
		_mode = (uint32_t)octalValueFromBuffer(
		    header + 100, 8, UINT32_MAX);
		_size = _toRead = (uint64_t)octalValueFromBuffer(
		    header + 124, 12, UINT64_MAX);
		_modificationDate = [[OFDate alloc]
		    initWithTimeIntervalSince1970:
		    (of_time_interval_t)octalValueFromBuffer(
		    header + 136, 12, UINTMAX_MAX)];
		_type = header[156];
		_targetFileName = [stringFromBuffer(header + 157, 100) copy];

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

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

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

			_deviceMajor = (uint32_t)octalValueFromBuffer(
			    header + 329, 8, UINT32_MAX);
			_deviceMinor = (uint32_t)octalValueFromBuffer(
			    header + 337, 8, UINT32_MAX);

			fileName = [OFString stringWithFormat: @"%@/%@",
			    stringFromBuffer(header + 345, 155), _fileName];
			[_fileName release];
			_fileName = [fileName copy];
		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_stream release];
	[_fileName release];
	[_modificationDate release];
	[_targetFileName release];
	[_owner release];
	[_group release];

	[super dealloc];
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{

Modified utils/ofzip/TarArchive.m from [5eeadf9d58] to [c120b18a1b].

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
			OFString *date = [[entry modificationDate]
			    localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];

			[of_stdout writeFormat:
			    @"\tSize: %" PRIu64 @" bytes\n"
			    @"\tModification date: %@\n",
			    [entry size], date];







		}

		if (app->_outputLevel >= 2) {
			switch ([entry type]) {
			case OF_TAR_ARCHIVE_ENTRY_TYPE_FILE:
				[of_stdout writeLine: @"\tType: 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]];
				break;
			case OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK:
				[of_stdout writeLine: @"\tType: Symbolic link"];
				[of_stdout writeFormat:
				    @"\tTarget file name: %@\n",
				    [entry targetFileName]];


























				break;
			default:
				[of_stdout writeLine: @"\tType: Unknown"];
				break;
			}
		}








>
>
>
>
>
>
>


















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







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
			OFString *date = [[entry modificationDate]
			    localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];

			[of_stdout writeFormat:
			    @"\tSize: %" PRIu64 @" bytes\n"
			    @"\tModification date: %@\n",
			    [entry size], date];

			if ([entry owner] != nil)
				[of_stdout writeFormat: @"\tOwner: %@\n",
							[entry owner]];
			if ([entry group] != nil)
				[of_stdout writeFormat: @"\tGroup: %@\n",
							[entry group]];
		}

		if (app->_outputLevel >= 2) {
			switch ([entry type]) {
			case OF_TAR_ARCHIVE_ENTRY_TYPE_FILE:
				[of_stdout writeLine: @"\tType: 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]];
				break;
			case OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK:
				[of_stdout writeLine: @"\tType: Symbolic link"];
				[of_stdout writeFormat:
				    @"\tTarget file name: %@\n",
				    [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_BLOCK_DEVICE:
				[of_stdout writeLine:
				    @"\tType: Block device"];
				[of_stdout writeFormat: @"\tDevice major: %d\n"
							@"\tDevice minor: %d\n",
							[entry deviceMajor],
							[entry deviceMinor]];
				break;
			case OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY:
				[of_stdout writeLine: @"\tType: Directory"];
				break;
			case OF_TAR_ARCHIVE_ENTRY_TYPE_FIFO:
				[of_stdout writeLine: @"\tType: FIFO"];
				break;
			case OF_TAR_ARCHIVE_ENTRY_TYPE_CONTIGUOUS_FILE:
				[of_stdout writeLine:
				    @"\tType: Contiguous file"];
				break;
			default:
				[of_stdout writeLine: @"\tType: Unknown"];
				break;
			}
		}