Comments (3)
Gatekeeper on macOS
阅读 potionfactory/LetsMove#56 和 sevengo8378/blog#1 。
macOS 的 Gatekeeper 安全机制会对不信任的软件包( Bundle ,在这里指 .app 文件夹)进行一些处理。来自于不信任来源的 .dmg 镜像文件中的软件包,或者从来自于不信任来源的 .zip 压缩文件中提取的软件包会被认为是不被信任的。你可以用ls -l@
命令查看这样的 .dmg 镜像文件、 .zip 压缩文件以及 .app 软件包的拓展文件属性( Extended file attributes ):
% ls -l@ /.../DMG_NAME.dmg /.../ZIP_NAME.zip /.../APPNAME.app
-rw-r--r--@ 1 USER_NAME staff ... DMG_NAME.dmg
...
com.apple.quarantine 57
-rw-r--r--@ 1 USER_NAME staff ... ZIP_NAME.zip
...
com.apple.quarantine 57
drwxr-xr-x@ 3 USER_NAME staff ... APPNAME.app
com.apple.quarantine 57
当这样的软件包被打开时,会弹出“无法确认开发者的身份”安全警告。在 Finder 中右键-“打开”该软件包,可以在警告弹出后继续运行程序。如果该软件包本身没有被用户在 Finder 中进行移动,在程序被执行之前,整个软件包将会被挂载到一个随机目录中( Path randomization ),接着再运行程序。随机目录的路径形式为/private/var/folders/hs/.../T/AppTranslocation/...
,软件包中的程序所在路径为/private/var/folders/hs/.../T/AppTranslocation/.../d/APPNAME.app/Contents/MacOS
:
% df -ha
Filesystem ... Mounted on
...
/.../APPNAME.app ... /private/var/folders/hs/.../T/AppTranslocation/...
这个随机目录是只读的(read-only
;同时也要注意nullfs
):
% mount
...
/Volumes/DMG_NAME/APPNAME.app on /private/var/folders/hs/.../T/AppTranslocation/... (nullfs, local, nodev, nosuid, read-only, noowners, quarantine, nobrowse, mounted by USER_NAME)
这就是 B4X 在 macOS 上报错“无法为配置创建目录”的原因。代码:
BesLyric-for-X/Entities/SettingManager.cpp
Lines 376 to 393 in 440094a
不过,只要使用 Finder 进行一次软件包的移动,就可以使软件包不被挂载到随机目录中,进而让程序对所在目录拥有“写”权限。这可能是 Finder 对文件的一些标志( Flag )进行了修改。
使用 Finder 将软件包从 .dmg 镜像文件中提取到任意位置也算作“使用 Finder 进行一次软件包的移动”。
不过,在程序所在目录存储数据仍然是不被推荐的。
* 可以尝试使用 Qt 的 (QDir(QCoreApplication::applicationDirPath())).entryInfoList({"."}).first().permissions()
获得程序所在目录的权限。对于在随机目录运行的软件包中的程序,结果为:
7555:/private/var/folders/hs/.../T/AppTranslocation/.../d/APPNAME.app/Contents/MacOS
对于在正常目录运行的软件包中的程序,结果为:
7755:/.../APPNAME.app/Contents/MacOS
结果中“ 7555 ”和“ 7755 ”的差异是比较奇怪的,因为在 Qt 的文档中有:
Warning: ... the semantics of ReadUser, WriteUser and ExeUser are platform-dependent: On Unix, the rights of the owner of the file are returned...
但是从上文的结果看, Owner 与 User 差了“写”权限。
直接用ls -la
查看权限:
% ls -la /private/var/folders/hs/.../T/AppTranslocation/.../d/APPNAME.app/Contents/MacOS
drwxr-xr-x@ 3 mac staff ... .
drwxr-xr-x@ 8 mac staff ... ..
-rwxr-xr-x@ 1 mac staff ... APPNAME
...
% ls -la /.../APPNAME.app/Contents/MacOS
drwxr-xr-x@ 3 mac staff ... .
drwxr-xr-x@ 8 mac staff ... ..
-rwxr-xr-x@ 1 mac staff ... APPNAME
...
并没有区别。
from beslyric-for-x.
AppImage, SquashFS and FUSE on Ubuntu
由 linuxdeployqt 进行依赖收集和打包的应用程序,生成的 AppImage 能够以单文件的形式在各个 Linux 发行版运行。现在的 AppImage 是一种使用 SquashFS 文件系统的镜像文件,当它被执行时,其中的内容将会由 FUSE 挂载到/tmp/
下的一个随机目录中,接着再运行程序。随机目录的路径形式为/tmp/.mount_APPNAME...
,镜像文件中的程序所在路径为/tmp/.mount_APPNAME.../usr/bin
:
$ df -haT
Filesystem Type ... Mounted on
...
AppImage_NAME.AppImage fuse.AppImage_NAME.AppImage ... /tmp/.mount_APPNAME...
这个随机目录是只读的(ro
):
$ cat /proc/mounts
...
AppImage_NAME.AppImage /tmp/.mount_APPNAME... fuse.AppImage_NAME.AppImage ro,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
这是 B4X 在 Ubuntu 上报错“无法为配置创建目录”的原因。
当然,在程序所在目录存储数据是不被推荐的。
* 可以尝试使用 Qt 的 (QDir(QCoreApplication::applicationDirPath())).entryInfoList({"."})
获得程序所在目录的信息,结果为空。查阅文档:
...
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
用ls -la
查看权限:
$ ls -la /tmp/.mount_APPNAME...
total ...
lrwxrwxrwx 1 root root ... AppRun -> usr/bin/APPNAME
-rw-rw-r-- 1 root root ... .DirIcon
-rw-rw-r-- 1 root root ... APPNAME.desktop
...
drwxrwxr-x 7 root root ... usr
$ sudo su
# ls -la /tmp/.mount_APPNAME...
ls: cannot access '/tmp/.mount_APPNAME...': Permission denied
这可能是由于 FUSE 本身的限制导致的。
from beslyric-for-x.
关于应该在哪里存储应用数据,这一点也一直比较头疼。
windows
针对用户 | C# 参考名 | cmd 变量名 | 例子 |
---|---|---|---|
全局多用户共用 | Environment.SpecialFolder.CommonApplicationData | %programdata% | C:\ProgramData |
当前漫游用户 | Environment.SpecialFolder.ApplicationData | %ApplicationData% | C:\Users\UserName\AppData\Roaming |
当前非漫游用户 | Environement.SpecialFolder.LocalApplicationData | %localappdata% | C:\Users\UserName\AppData\Local |
windows 这些目录应该比较推荐的, 应该也没有 权限问题,可以考虑 [%AppData% | C:/Users/UserName/AppData/Roaming] /AppData
mac os
似乎可以考虑 [ ~ | ${HOME} | /Users/UserName ] /Library/Application Support/AppData
, 不过还是得解决前面提到的 Gatekeeper
问题
参考1、参考2
linux
类似 mac os, 放在 [ ~ | $HOME | /home/UserName ] /<APPNAME>
,权限问题还不太清楚
总的来说,可以考虑的各个平台的存储程序数据的路径有:
平台 | 可参考路径 |
---|---|
linux | [ ~ | $HOME | /home/ ] /AppData |
mac | [ ~ | ${HOME} | /Users/UserName ] /Library/Application Support/AppData |
windows | [%AppData% | C:/Users/UserName/AppData/Roaming ]/AppData |
from beslyric-for-x.
Related Issues (20)
- 纠正错误提示“成功失败”,同时优化内容过长而导致显示不全的提示
- 皮肤盒子箭头对不齐,不好看,删掉 HOT 1
- 在程序里标注 BesLyric-for-X 使用的图标来源
- 可以帮您打包到Arch/Manjaro的AUR源里吗 HOT 4
- 完善登录信息的收集 HOT 4
- Migrate from qmake to CMake | 从 qmake 迁移到 CMake
- Remove the source code copied from FFmpeg | 移除从 FFmpeg 复制的源代码
- Introduce TagLib to process the information in audio files | 引入 TagLib 以处理音频文件中的信息
- Analyze the code with tools before committing | 在提交前使用工具分析代码
- Format the code with tools before committing | 在提交前使用工具格式化代码
- Introduce GitHub Actions | 引入 GitHub Actions
- End the support for 32-bit Windows | 停止对 32 位 Windows 的支持
- End the support for macOS 10.13 | 停止对 macOS 10.13 的支持
- Migrate from Qt 5 to Qt 6 | 从 Qt 5 迁移到 Qt 6
- 无法搜索歌曲? HOT 9
- 无法播放部分WAV文件 HOT 4
- wav 格式音乐播放后,没有声音 HOT 1
- flac ape m4a aac 不能通过拖放添加音乐 HOT 2
- 音樂文件導入後,點擊開始製作沒有聲音 HOT 1
- 在俄罗斯使用VPN可以下载国内歌曲,但是无法搜索和下载歌词 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beslyric-for-x.