ObjFW  Check-in [8aa7f964bc]

Overview
Comment:OFURL: Return a proper URL for +[fileURLWithPath:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8aa7f964bc4003a2907d1f9466f61b631321bb5f85285d75b39449815874ca95
User & Date: js on 2017-10-28 23:52:32
Other Links: manifest | tags
Context
2017-10-29
00:41
Fix conversion between URL and path on Win32 check-in: b83d1414b1 user: js tags: trunk
2017-10-28
23:52
OFURL: Return a proper URL for +[fileURLWithPath:] check-in: 8aa7f964bc user: js tags: trunk
21:26
OFFileManager: Add -[currentDirectoryURL] check-in: 9713afbd6d user: js tags: trunk
Changes

Modified src/OFFileManager.m from [63200da91b] to [d45420d7bb].

287
288
289
290
291
292
293

294
295


296
297








298
299
300
301
302
303
304
287
288
289
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313







+


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







#endif
}

- (OFURL *)currentDirectoryURL
{
	OFMutableURL *URL = [OFMutableURL URL];
	void *pool = objc_autoreleasePoolPush();
	OFString *path;

	[URL setScheme: @"file"];

#if OF_PATH_DELIMITER != '/'
	[URL setPath: [[[self currentDirectoryPath] pathComponents]
	    componentsJoinedByString: @"/"]];
	path = [[[self currentDirectoryPath] pathComponents]
	    componentsJoinedByString: @"/"];
#else
	path = [self currentDirectoryPath];
#endif

	[URL setPath: [path stringByAppendingString: @"/"]];

	[URL makeImmutable];

	objc_autoreleasePoolPop(pool);

	return URL;
}

Modified src/OFURL.h from [eee6f35b3b] to [b68aeab9b8].

96
97
98
99
100
101
102

103
104
105
106
107
108
109

110
111
112
113
114
115
116
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118







+







+







 * @param string A string describing a URL
 * @param URL An URL to which the string is relative
 * @return A new, autoreleased OFURL
 */
+ (instancetype)URLWithString: (OFString *)string
		relativeToURL: (OFURL *)URL;

#ifdef OF_HAVE_FILES
/*!
 * @brief Creates a new URL with the specified local file path.
 *
 * @param path The local file path
 * @return A new, autoreleased OFURL
 */
+ (instancetype)fileURLWithPath: (OFString *)path;
#endif

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated OFURL with the specified string.
 *
 * @param string A string describing a URL

Modified src/OFURL.m from [6274573b21] to [5a68687d28].

18
19
20
21
22
23
24



25
26
27
28
29
30
31
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+
+
+








#include <stdlib.h>
#include <string.h>

#import "OFURL.h"
#import "OFURL+Private.h"
#import "OFArray.h"
#ifdef OF_HAVE_FILES
# import "OFFileManager.h"
#endif
#import "OFNumber.h"
#import "OFString.h"
#import "OFXMLElement.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
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
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







+


-

+
+

+
+
+
-
-
+
+
+
+

-
+
+
+
+



-
+

+







+ (instancetype)URLWithString: (OFString *)string
		relativeToURL: (OFURL *)URL
{
	return [[[self alloc] initWithString: string
			       relativeToURL: URL] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)fileURLWithPath: (OFString *)path
{
	OFMutableURL *URL = [OFMutableURL URL];
	void *pool = objc_autoreleasePoolPush();
	OFFileManager *fileManager = [OFFileManager defaultManager];
	OFURL *currentDirectoryURL, *URL;

	if (![path hasSuffix: OF_PATH_DELIMITER_STRING] &&
	    [fileManager directoryExistsAtPath: path])
		path = [path stringByAppendingString: @"/"];
	[URL setScheme: @"file"];
	[URL setPath: [[path pathComponents] componentsJoinedByString: @"/"]];

# if OF_PATH_DELIMITER != '/'
	path = [[path pathComponents] componentsJoinedByString: @"/"];
# endif

	[URL makeImmutable];
	currentDirectoryURL =
	    [[OFFileManager defaultManager] currentDirectoryURL];
	URL = [[OFURL alloc] initWithString: path
			      relativeToURL: currentDirectoryURL];

	objc_autoreleasePoolPop(pool);

	return URL;
	return [URL autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_init