Skip to content

Commit 17ed7fd

Browse files
committed
Fixed prefix path for FHS Installed Bundles
- Updated Bundle.url(forAuxiliaryExecutable:) return type as URL - Added FindExecutable test in TestBundle - Cleaned TestBundle.swift
1 parent 833f572 commit 17ed7fd

File tree

3 files changed

+142
-123
lines changed

3 files changed

+142
-123
lines changed

CoreFoundation/PlugIn.subproj/CFBundle_Executable.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,15 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL
207207
if (lookupMainExe && bundle && bundle->_isFHSInstalledBundle) {
208208
// For a FHS installed bundle, the URL points to share/Bundle.resources, and the binary is in:
209209

210-
CFURLRef prefix = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorSystemDefault, url);
211-
210+
CFURLRef sharePath = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorSystemDefault, url);
211+
CFURLRef prefixPath = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorSystemDefault, sharePath);
212+
CFRelease(sharePath);
213+
212214
CFStringRef directories[] = { _CFBundleFHSDirectoriesInExecutableSearchOrder };
213215
size_t directoriesCount = sizeof(directories) / sizeof(directories[0]);
214216

215217
for (size_t i = 0; i < directoriesCount; i++) {
216-
CFURLRef where = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, prefix, directories[i], true);
218+
CFURLRef where = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, prefixPath, directories[i], true);
217219
executableURL = _CFBundleCopyExecutableURLRaw(where, executableName);
218220
CFRelease(where);
219221

@@ -223,7 +225,7 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL
223225
}
224226
}
225227

226-
CFRelease(prefix);
228+
CFRelease(prefixPath);
227229
}
228230
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
229231

@@ -290,11 +292,7 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL
290292
if (lookupMainExe && !ignoreCache && bundle && executableURL) {
291293
// We found it. Cache the path.
292294
CFURLRef absURL = CFURLCopyAbsoluteURL(executableURL);
293-
#if DEPLOYMENT_TARGET_WINDOWS
294-
executablePath = CFURLCopyFileSystemPath(absURL, kCFURLWindowsPathStyle);
295-
#else
296-
executablePath = CFURLCopyFileSystemPath(absURL, kCFURLPOSIXPathStyle);
297-
#endif
295+
executablePath = CFURLCopyFileSystemPath(absURL, PLATFORM_PATH_STYLE);
298296
CFRelease(absURL);
299297
__CFLock(&bundle->_lock);
300298
bundle->_executablePath = (CFStringRef)CFRetain(executablePath);

Foundation/Bundle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ open class Bundle: NSObject {
115115
return CFBundleCopyExecutableURL(_bundle)?._swiftObject
116116
}
117117

118-
open func url(forAuxiliaryExecutable executableName: String) -> NSURL? {
119-
return CFBundleCopyAuxiliaryExecutableURL(_bundle, executableName._cfObject)?._nsObject
118+
open func url(forAuxiliaryExecutable executableName: String) -> URL? {
119+
return CFBundleCopyAuxiliaryExecutableURL(_bundle, executableName._cfObject)?._swiftObject
120120
}
121121

122122
open var privateFrameworksURL: URL? {

0 commit comments

Comments
 (0)