首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将数据写入沙箱外的/usr/libexec/cups/filter/

如何将数据写入沙箱外的/usr/libexec/cups/filter/
EN

Stack Overflow用户
提问于 2019-07-29 13:40:56
回答 1查看 165关注 0票数 0

我在沙箱中有一个应用程序(用于App部署),它需要在/usr/libexec/cups/filter/中安装一个文件,将两个文件安装到/private/etc/cups/中。此安装不是定期完成的,而是在从UI执行时完成的。当要求“全磁盘访问”或通过其他方法时,这是可能的吗?

代码语言:javascript
复制
    var inFilePath = Bundle.main.url(forResource: "thnucups", withExtension: nil, subdirectory: "thnuclnt/x86_64-darwin")!

    let inFile: FileHandle? = try! FileHandle(forReadingFrom: inFilePath)

    let data = inFile?.readDataToEndOfFile()

    inFile?.closeFile()

    var destPath = "/usr/libexec/cups/filter/test";

    let outFileUrl = URL(fileURLWithPath: destPath)

    FileManager.default.createFile(atPath: destPath, contents: nil, attributes: nil)

    let outFile: FileHandle? = try! FileHandle(forWritingTo: outFileUrl)

    outFile?.write(data!)

    outFile?.closeFile()

让outFile: FileHandle?=试试!FileHandle(forWritingTo: outFileUrl)引发以下异常:

2019-07-29 15:16:46.985094+0200 ezeep连接器用于macOS 33450:488523致命错误:“尝试!”表达式意外引发错误: Error Domain=NSCocoaErrorDomain Code=4“文件”“test”不存在。UserInfo={NSFilePath=/usr/libexec/cups/filter/test,NSUnderlyingError=0x600000c5e610 { Domain=NSPOSIXErrorDomain Code=2“没有这样的文件或目录”}}:文件/Users/rwelz/Documents/Develop/PROJEKTE/ThinPrint/in GIT/ThinPrint/EZEEP/Xcode/ezeep用于macOS/ezeep,用于macOS/AppDelegate./Users/rwelz/Documents/Develop/PROJEKTE/ThinPrint/in,第146行

现在有:

代码语言:javascript
复制
    let dialog = NSOpenPanel()

    dialog.allowsMultipleSelection = false
    dialog.canCreateDirectories = false
    dialog.canChooseDirectories = true
    dialog.canChooseFiles = false

    dialog.begin
    { (result) -> Void in
        if result == .OK
        {
            let url = dialog.url

            do
            {
                try data?.write(to: outFileUrl)
            }
            catch
            {
                print("Error: Exception caught: " + error.localizedDescription)

            }
        }
    }

我不再获得异常,但由于/usr/libexec/cups/filter具有drwxr-xr-x根轮(在不以root用户身份运行时没有写入访问权限),我得到的是“您没有权限在文件夹筛选器中保存文件”。

我需要以root的形式运行,沙箱中不允许这样做。

还有其他想法吗?

向罗伯特问好

EN

回答 1

Stack Overflow用户

发布于 2019-11-28 09:35:18

我决定构建一个pkg安装程序,它可以从我的沙箱应用程序中的菜单项保存到磁盘。当应用程序第一次启动时,还提供了保存对话框。然后,用户必须打开pkg并作为管理员进行身份验证才能开始安装。在pkg的飞行后脚本中,它向应用程序发送一个苹果事件( osascript -e 'tell application PATH to start_action‘,让应用程序知道它可以继续运行。

实际上,安装程序将一个虚拟ppd与cups过滤器一起安装到/Library/PPDs/PPDs/Content/Resources/,我的应用程序查询cups以确保安装了/usr/libexec/cups/filer/ my _filter。

现在,让我们看看苹果在审查我的应用程序时对该解决方案的看法;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57255146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档