我正在尝试以编程方式安装一些 WebDAV 和 SMB 共享,并且我想为卷指定默认名称以外的特定名称。例如,如果我挂载
我希望它在 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/