Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CFBundle::private_frameworks_url() exposing CFBundleCopyPrivateFr… #103

Merged
merged 2 commits into from Jun 16, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Add CFBundle::private_frameworks_url() exposing CFBundleCopyPrivateFr…

…ameworksURL().
  • Loading branch information
nikhilm committed Jun 16, 2017
commit d58b72d211b585735118f606808f1d183d57c532
@@ -32,4 +32,5 @@ extern {

pub fn CFBundleGetTypeID() -> CFTypeID;
pub fn CFBundleCopyExecutableURL(bundle: CFBundleRef) -> CFURLRef;
pub fn CFBundleCopyPrivateFrameworksURL(bundle: CFBundleRef) -> CFURLRef;
}
@@ -63,6 +63,17 @@ impl CFBundle {
}
}
}

pub fn private_frameworks_url(&self) -> Option<CFURL> {
unsafe {
let fw_url = CFBundleCopyPrivateFrameworksURL(self.0);
if fw_url.is_null() {
None
} else {
Some(TCFType::wrap_under_create_rule(fw_url))
}
}
}
}

impl_TCFType!(CFBundle, CFBundleRef, CFBundleGetTypeID);
@@ -74,10 +85,35 @@ fn safari_executable_url() {

let cfstr_path = CFString::from_static_string("/Applications/Safari.app");
let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
let cfurl_executable = CFBundle::new(cfurl_path).expect("Safari not present").executable_url();
let cfurl_executable = CFBundle::new(cfurl_path)
.expect("Safari not present")
.executable_url();
assert!(cfurl_executable.is_some());
assert_eq!(cfurl_executable
.unwrap()
.absolute()
.get_file_system_path(kCFURLPOSIXPathStyle)
.to_string(),
"/Applications/Safari.app/Contents/MacOS/Safari");
}

#[test]
fn safari_private_frameworks_url() {
use string::CFString;
use url::{CFURL, kCFURLPOSIXPathStyle};

let cfstr_path = CFString::from_static_string("/Applications/Safari.app");
let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
let cfurl_executable = CFBundle::new(cfurl_path)
.expect("Safari not present")
.private_frameworks_url();
assert!(cfurl_executable.is_some());
assert_eq!(cfurl_executable.unwrap().absolute().get_file_system_path(kCFURLPOSIXPathStyle).to_string(),
"/Applications/Safari.app/Contents/MacOS/Safari");
assert_eq!(cfurl_executable
.unwrap()
.absolute()
.get_file_system_path(kCFURLPOSIXPathStyle)
.to_string(),
"/Applications/Safari.app/Contents/Frameworks");
}

#[test]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.