gpt4 book ai didi

specifications - 程序应该创建 XDG 文件夹吗?

转载 作者:行者123 更新时间:2023-12-04 17:59:53 24 4
gpt4 key购买 nike

假设我正在编写一个程序,我希望它遵循 XDG 基本目录规范来放置文件(如果设置了 foo,应用程序 $XDG_CONFIG_HOME/foo 使用 XDG_CONFIG_HOME 作为配置文件的目录且非空白或 ~/.config/foo ,或者如果主目录甚至无法解析则失败并显示错误)。

对于例如 XDG_CONFIG_HOME 的情况是否有正确/指定的行为?已设置且非空白,但该目录不存在?或者如果没有这样的变量,和~/.config不存在?预计我的程序会尝试创建它吗?或者该目录的不存在是否被认为是环境/系统部分的错误,我的程序应该避免对此做任何事情(只是因为错误而保释)?

注意:我不是问我是否应该创建 ~/.config/foo - 显然是的;我在问我是否应该创建 ~/.config本身,如果它不存在。

(更迂腐:显然某些程序应该创建它们 - 问题是这样做是否仅仅是系统/桌面/用户的工作,或者如果相关目录不存在,是否有任何程序应该尝试创建相关目录?)

我试过阅读 XDG Base Directory Specification ,这表示在尝试写入其文件时,程序可能会创建必需的目录,但尚不清楚这是否仅指 XDG 基目录中应用程序的特定/“个人”子目录,或者这是否适用于XDG 基目录本身。

附言通常我很清楚要使用什么标签,但在这里我真的不确定:请编辑这篇文章或提出改进建议以提供适当的标签。

最佳答案

来自 XDG Base Directory Specification :

If, when attempting to write a file, the destination directory is non-existant an attempt should be made to create it with permission 0700. If the destination directory exists already the permissions should not be changed. The application should be prepared to handle the case where the file could not be written, either because the directory was non-existant and could not be created, or for any other reason. In such case it may chose to present an error message to the user.



我会解释这一点,因此应用程序应该尝试创建 XDG 基目录(或目标所需的任何目录),并且仅在无法创建时才显示错误。

关于specifications - 程序应该创建 XDG 文件夹吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36808455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com