ObjFW  Check-in [c62f1c55ac]

Overview
Comment:OFOpenItemFailedException: Remove path
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c62f1c55ac8ef6af061539e5ebe2e75d4a6aaf943c795837c6c7cef8e87d96c2
User & Date: js on 2022-04-25 19:09:29
Other Links: manifest | tags
Context
2022-04-25
20:09
Revert "OFOpenItemFailedException: Remove path" check-in: 1185c1cd3d user: js tags: trunk
19:14
More reordering for consistency check-in: 8cb6fafdc0 user: js tags: trunk
19:09
OFOpenItemFailedException: Remove path check-in: c62f1c55ac user: js tags: trunk
19:01
More declaration reordering check-in: d9fb19b0a1 user: js tags: trunk
Changes

Modified src/OFFile.m from [6d43aa3c50] to [ca29a7a55a].

234
235
236
237
238
239
240
241
242
243



244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
234
235
236
237
238
239
240



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261







-
-
-
+
+
+










+







			handle = open(
			    [path cStringWithEncoding: [OFLocale encoding]],
			    flags, 0666);
# endif

		if (handle == -1)
			@throw [OFOpenItemFailedException
			    exceptionWithPath: path
					 mode: mode
					errNo: errno];
			    exceptionWithURL: [OFURL fileURLWithPath: path]
					mode: mode
				       errNo: errno];
#else
		handle = OFAllocMemory(1, sizeof(*handle));
		@try {
			if ((flags = parseMode(mode.UTF8String,
			    &handle->append)) == -1)
				@throw [OFInvalidArgumentException exception];

			if ((handle->handle = Open([path cStringWithEncoding:
			    [OFLocale encoding]], flags)) == 0) {
				int errNo;
				OFURL *URL;

				switch (IoErr()) {
				case ERROR_OBJECT_IN_USE:
				case ERROR_DISK_NOT_VALIDATED:
					errNo = EBUSY;
					break;
				case ERROR_OBJECT_NOT_FOUND:
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
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







+

-
-
-
+
+
+












+
+


-
-
-
+
+
+







					errNo = EACCES;
					break;
				default:
					errNo = 0;
					break;
				}

				URL = [OFURL fileURLWithPath: path];
				@throw [OFOpenItemFailedException
				    exceptionWithPath: path
						 mode: mode
						errNo: errNo];
				    exceptionWithURL: URL
						mode: mode
					       errNo: errNo];
			}

			if (handle->append) {
# if defined(OF_MORPHOS)
				if (Seek64(handle->handle, 0,
				    OFFSET_END) == -1) {
# elif defined(OF_AMIGAOS4)
				if (ChangeFilePosition(handle->handle, 0,
				    OFFSET_END) == -1) {
# else
				if (Seek(handle->handle, 0, OFFSET_END) == -1) {
# endif
					OFURL *URL =
					    [OFURL fileURLWithPath: path];
					Close(handle->handle);
					@throw [OFOpenItemFailedException
					    exceptionWithPath: path
							 mode: mode
							errNo: EIO];
					    exceptionWithURL: URL
							mode: mode
						       errNo: EIO];
				}
			}

			Forbid();

			handle->previous = NULL;
			handle->next = firstHandle;

Modified src/OFString.m from [05a5b5b79b] to [f2f791550d].

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011



1012
1013
1014
1015
1016
1017
1018
1002
1003
1004
1005
1006
1007
1008



1009
1010
1011
1012
1013
1014
1015
1016
1017
1018







-
-
-
+
+
+







		OFFile *file = nil;

		@try {
			fileSize = [[OFFileManager defaultManager]
			    attributesOfItemAtPath: path].fileSize;
		} @catch (OFRetrieveItemAttributesFailedException *e) {
			@throw [OFOpenItemFailedException
			    exceptionWithPath: path
					 mode: @"r"
					errNo: e.errNo];
			    exceptionWithURL: [OFURL fileURLWithPath: path]
					mode: @"r"
				       errNo: e.errNo];
		}

		objc_autoreleasePoolPop(pool);

# if ULLONG_MAX > SIZE_MAX
		if (fileSize > SIZE_MAX)
			@throw [OFOutOfRangeException exception];

Modified src/OFZIPArchive.m from [2bbedc5f4d] to [b017bd11e7].

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

40
41
42
43
44
45
46







-







#import "OFInflate64Stream.h"

#import "OFChecksumMismatchException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSeekFailedException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedVersionException.h"
#import "OFWriteFailedException.h"

/*
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454
437
438
439
440
441
442
443

444


445
446
447
448
449
450
451







-
+
-
-







	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_mode != modeRead)
		@throw [OFInvalidArgumentException exception];

	if ((entry = [_pathToEntryMap objectForKey: path]) == nil)
		@throw [OFOpenItemFailedException exceptionWithPath: path
		@throw [OFInvalidArgumentException exception];
							       mode: @"r"
							      errNo: ENOENT];

	[self of_closeLastReturnedStream];

	offset64 = entry.of_localFileHeaderOffset;
	if (offset64 < 0 || (OFFileOffset)offset64 != offset64)
		@throw [OFOutOfRangeException exception];

494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509
510
511
491
492
493
494
495
496
497

498



499
500
501
502
503
504
505







-
+
-
-
-







	if (_mode != modeWrite && _mode != modeAppend)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();
	entry = [[entry_ mutableCopy] autorelease];

	if ([_pathToEntryMap objectForKey: entry.fileName] != nil)
		@throw [OFOpenItemFailedException
		@throw [OFInvalidArgumentException exception];
		    exceptionWithPath: entry.fileName
				 mode: @"w"
				errNo: EEXIST];

	if (entry.compressionMethod != OFZIPArchiveEntryCompressionMethodNone)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
								 object: self];

	[self of_closeLastReturnedStream];

Modified src/exceptions/OFOpenItemFailedException.h from [f84d68c6f2] to [bc86e5de05].

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
23
24
25
26
27
28
29


30
31

32
33
34
35
36
37

38





39
40
41
42
43
44
45







-
-
+
+
-






-
+
-
-
-
-
-







 * @class OFOpenItemFailedException \
 *	  OFOpenItemFailedException.h ObjFW/OFOpenItemFailedException.h
 *
 * @brief An exception indicating an item could not be opened.
 */
@interface OFOpenItemFailedException: OFException
{
	OFURL *_Nullable _URL;
	OFString *_Nullable _path;
	OFURL *_URL;
	OFString *_Nullable _mode;
	OFString *_mode;
	int _errNo;
}

/**
 * @brief The URL of the item which could not be opened.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFURL *URL;
@property (readonly, nonatomic) OFURL *URL;

/**
 * @brief The path of the item which could not be opened.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path;

/**
 * @brief The mode in which the item should have been opened.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *mode;

/**
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
57
58
59
60
61
62
63












64
65
66
67
68
69
70
71
72
73
74
75












76
77
78
79







-
-
-
-
-
-
-
-
-
-
-
-












-
-
-
-
-
-
-
-
-
-
-
-




 */
+ (instancetype)exceptionWithURL: (OFURL *)URL
			    mode: (nullable OFString *)mode
			   errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased open item failed exception.
 *
 * @param path The path of the item which could not be opened
 * @param mode A string with the mode in which the item should have been opened
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased open item failed exception
 */
+ (instancetype)exceptionWithPath: (OFString *)path
			     mode: (nullable OFString *)mode
			    errNo: (int)errNo;

/**
 * @brief Initializes an already allocated open item failed exception.
 *
 * @param URL The URL of the item which could not be opened
 * @param mode A string with the mode in which the item should have been opened
 * @param errNo The errno of the error that occurred
 * @return An initialized open item failed exception
 */
- (instancetype)initWithURL: (OFURL *)URL
		       mode: (nullable OFString *)mode
		      errNo: (int)errNo;

/**
 * @brief Initializes an already allocated open item failed exception.
 *
 * @param path The path of the item which could not be opened
 * @param mode A string with the mode in which the item should have been opened
 * @param errNo The errno of the error that occurred
 * @return An initialized open item failed exception
 */
- (instancetype)initWithPath: (OFString *)path
			mode: (nullable OFString *)mode
		       errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFOpenItemFailedException.m from [2ae9f29630] to [1a7c4cc489].

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







-
+
-
-
-
-
-










-
+
-
-

-
-
-
-
-
+
-
-
-




















-
+
-
-

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





-







-
-
-
-
-
-
-



-
+


-
+


#include "config.h"

#import "OFOpenItemFailedException.h"
#import "OFString.h"
#import "OFURL.h"

@implementation OFOpenItemFailedException
@synthesize URL = _URL, path = _path, mode = _mode, errNo = _errNo;
@synthesize URL = _URL, mode = _mode, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL
			    mode: (OFString *)mode
			   errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL
				     mode: mode
				    errNo: errNo] autorelease];
}

+ (instancetype)exceptionWithPath: (OFString *)path
+ (instancetype)exception
			     mode: (OFString *)mode
			    errNo: (int)errNo
{
	return [[[self alloc] initWithPath: path
				      mode: mode
				     errNo: errNo] autorelease];
}

	OF_UNRECOGNIZED_SELECTOR
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithURL: (OFURL *)URL
		       mode: (OFString *)mode
		      errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_mode = [mode copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithPath: (OFString *)path
- (instancetype)init
			mode: (OFString *)mode
		       errNo: (int)errNo
{
	self = [super init];

	OF_INVALID_INIT_METHOD
	@try {
		_path = [path copy];
		_mode = [mode copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_path release];
	[_mode release];

	[super dealloc];
}

- (OFString *)description
{
	id item = nil;

	if (_URL != nil)
		item = _URL;
	else if (_path != nil)
		item = _path;

	if (_mode != nil)
		return [OFString stringWithFormat:
		    @"Failed to open item %@ with mode %@: %@",
		    item, _mode, OFStrError(_errNo)];
		    _URL, _mode, OFStrError(_errNo)];
	else
		return [OFString stringWithFormat:
		    @"Failed to open item %@: %@", item, OFStrError(_errNo)];
		    @"Failed to open item %@: %@", _URL, OFStrError(_errNo)];
}
@end