macos - NetFSMountURLSync 无法使用自定义挂载点?

标签 macos osx-mountain-lion

我正在尝试以编程方式安装一些 WebDAV 和 SMB 共享,并且我想为卷指定默认名称以外的特定名称。例如,如果我挂载

https://my.sharepoint.school.edu/personal/grigutis

我希望它在 Finder 中显示为

/Volumes/My SharePoint Site
or
~/Desktop/My SharePoint Site

代替

/Volumes/grigutis
or
~/Desktop/grigutis

我可以用 mount_webdav 命令做到这一点:

$ mkdir /Volumes/My\ SharePoint\ Site
$ mount_webdav -s -i https://my.sharepoint.school.edu/personal/grigutis /Volumes/My\ SharePoint\ Site
or
$ mkdir ~/Desktop/My\ SharePoint\ Site
$ mount_webdav -s -i https://my.sharepoint.school.edu/personal/grigutis ~/Desktop/My\ SharePoint\ Site

但我无法使用 NetFSMountURLSync(假设我已经创建了目录):

NSURL *url = [NSURL URLWithString:@"https://my.sharepoint.school.edu/personal/grigutis"];

NSURL *mountpath = [NSURL fileURLWithPath:@"/Volumes/My SharePoint Site" isDirectory:YES];
or
NSURL *mountpath = [NSURL fileURLWithPath:[@"~/Desktop/My SharePoint Site" stringByExpandingTildeInPath] isDirectory:YES];

CFArrayRef mountpoints = NULL;
int result = 0;
result = NetFSMountURLSync((__bridge CFURLRef)url,
    (__bridge CFURLRef)mountpath,
    CFSTR("Kerberos"),
    CFSTR("NoPassword"),
    NULL,
    NULL,
    &mountpoints);

如果我尝试安装到/Volumes/My SharePoint Site,我会看到 Finder 对话框:

'There was a problem connecting to the server "my.sharepoint.school.edu". You do not have permission to access this server.'

并且该函数返回结果 13(权限被拒绝)。

如果我尝试挂载到 ~/Desktop/My SharePoint 网站,那么它会像这样挂载

~/Desktop/My SharePoint Site/grigutis

这不是我想要的。我已经提交了 a bug report对这个。有任何想法吗?如果可能的话,我想避免使用 NSTask。

最佳答案

预先创建挂载点,并在挂载选项中启用kNetFSMountAtMountDirKey:

CFMutableDictionaryRef mountOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(mountOpts, kNetFSMountAtMountDirKey, CFSTR("true"));
int ret = NetFSMountURLSync(
    (__bridge CFURLRef) url,
    (__bridge CFURLRef) mountPath,
    NULL,
    NULL,
    0,
    mountOpts,
    &mountPoints
);

关于macos - NetFSMountURLSync 无法使用自定义挂载点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13729880/

相关文章:

macos - 为什么我在 OS X 上使用 vim 时没有 crontab 条目?

php - 如何在 macOS Mojave 上启用 PHP Intl 扩展?

macos - 在 mac 中为 libc 生成 ctags

ruby-on-rails - Phusion Passenger 无法在 Mountain Lion 中编译

mysql - 山狮 : Can't connect to local MySQL server through socket '/tmp/mysql.sock'

swift - 创建 AKDelay 时,_AVAE_Check : required condition is false: [AVAudioEngine. mm :353:AttachNode: (node ! = nil)]

swift - 如果我有两个 TextView ,如何检查 NSTextView 何时更改?

phpunit - OSX 10.8 山狮 PEAR/PHPUnit 不工作

macos - Mac代码签名: Bypass the Keychain Access private key prompt from Terminal

更新到 OSX Mountain Lion 后 PHP mail() 不再有效