What does git mean by, “unable to migrate objects to permanent storage”?

之前偶尔发现提交代码会出现被拒绝情况,一开始以为可以用 gc 来解决问题,或者通过创建创建新分支或者重新提交代码来规避,然后发现被拒绝概率越来越高。遇到问题解决问题。

各种 google、百度加 stackOverflow,终于在 stackOverflow 上面看到一种解释,主要针对较高版本 git 和 gitlab,本地在提交 commit 的时候需要先提交到 tmp_objdir_migrate 然后再提交到仓库里面

    /*
     * Now we'll start writing out refs, which means the objects need
     * to be in their final positions so that other processes can see them.
     */
    if (tmp_objdir_migrate(tmp_objdir) < 0) {
        for (cmd = commands; cmd; cmd = cmd->next) {
            if (!cmd->error_string)
                cmd->error_string = "unable to migrate objects to permanent storage";
        }
        return;
    }
tmp_objdir = NULL;

Quarantine Environment

When receive-pack takes in objects, they are placed into a temporary “quarantine” directory within the $GIT_DIR/objects directory and migrated into the main object store only after the pre-receive hook has completed. If the push fails before then, the temporary directory is removed entirely.

This has a few user-visible effects and caveats:

  1. Pushes which fail due to problems with the incoming pack, missing objects, or due to the pre-receive hook will not leave any on-disk data. This is usually helpful to prevent repeated failed pushes from filling up your disk, but can make debugging more challenging.
  2. Any objects created by the pre-receive hook will be created in the quarantine directory (and migrated only if it succeeds).
  3. The pre-receive hook MUST NOT update any refs to point to quarantined objects. Other programs accessing the repository will not be able to see the objects (and if the pre-receive hook fails, those refs would become corrupted).

根据被拒绝的 log:./objects/c5/77e0eb9f2a855232d6b26e957ad71c431fdbaa: Permission denied 我们知道这个目录文件夹出问题了,于是我们想去找到服务器项目所在的路径,发现里面空空如也,一般项目路径下面会有 xx.git 代表这个仓库所在文件夹,然而没有,貌似只有 @hash 里面有很多不规则命名的文件夹。

一开始以为 git 文件夹被谁意外删掉了,然而 gitlab 网页加载正常,完全没有被删掉的异常表现。之前修复问题的时候弄坏过 git 项目,弄坏了的 git 项目,网页是会加载失败。

于是去看看 gitlab 相关知识,看了相关文档,原来项目路径都被放到 @hash 这个文件夹下面了,要查到项目具体路径,提供了两种方法,一种是通过 gitlab 网页客户端的 admin 后台,另外一种是通过 gitlab rail 命令行后台,通过

Project.find(16).disk_path // id 可以到项目设置里面看得到,不需要太高权限
Project.find_by_full_path('group/project').disk_path

都可以找到具体路径

修复

于是找到路径,查看项目的 c5 路径权限,权限果然不对,所有者居然是 root 不是 git,导致 git 写入失败,最终通过修改文件夹所有者改为 git 之后,提交成功

gitlab hash 文件夹文档:https://docs.gitlab.com/ee/administration/repository_storage_types.html
https://docs.gitlab.com/ee/user/admin_area/index.html#administering-projects
https://docs.gitlab.com/ee/administration/operations/rails_console.html#starting-a-rails-console-session

Linux 文件夹权限说明:
https://www.cnblogs.com/sxdcgaq8080/p/7498906.html

git push 失败 Stack Overflow 资料:
https://stackoverflow.com/questions/42214667/what-does-git-mean-by-unable-to-migrate-objects-to-permanent-storage
https://stackoverflow.com/questions/49627374/git-remote-rejected-unable-to-migrate-objects-to-permanent-storage

Android多语言国际化适配

一、6.0及以下语言设置界面

在Android 6.0及以前的语言设置都是单一的语言,只能选一种语言

二、7.0及以下多国语言设置界面

在Android 7.0开始允许用户在设置的语言配置中选择多个语言设置

从上面测试种我们可以得出在Android 7.0中资源加载的结论有:

App资源的加载首先会去寻找系统语言对应的资源(简体中文),如果找不到会去找系统语言所属的语言(中文),如果没找到就会去找在设置中的其他语言(美国英语)看看有没有对应的资源,如果也没有就会去加载默认资源。

App资源的加载首先会去寻找系统语言对应的资源(英国英文),如果没找到的话,会去寻找系统语言所属的语言(英文),如果也没找到的话,就会去寻找系统语言所属的语言的其他分支(美国英文)。

结合以上两条结论可以推出:首先App会去寻找与系统设置的第一语言最匹配的资源,如果没找到就会去寻找系统语言所属的语言的资源,也没找到的话就去找系统语言所属的语言的其他分支资源,如果第一语言的资源都没有找到,就会去看看有没有设置多个语言,如果有就看看有没有和第二语言最匹配的资源,如果没有就会去寻找第二语言所属的语言的资源,还没有的话就去寻找第二语言所属的语言的其他分支的资源,如果也没有,就去找第三语言、第四语言等等语言的资源,如果都没有就去加载默认资源,如果默认资源也没有就异常了。

三、简繁语言

不同国家或地区可能采用不同类型的中文 (语言)。一般情况而言简繁可以按照地区区分

然而我们通过设备可以对香港地区、澳门地区设置简体中文

当应用启动的时候,系统会根据当前的语言环境自动去匹配对应的values文件夹,匹配规则如下:
7.0之前,先匹配与当前应用Configuration语言一致的资源(language,country相同),如没有再匹配language一致的资源(命名中只有language,如values-en),如无则使用默认资源。
7.0之后,系统语言设置中可添加多个语言,优先匹配规则与上述一样,不过添加了可匹配同一语言不同国家的资源,即language与country都没匹配上,也可匹配同一个language但不同country的资源,即是同一父项下的不同子项。
如果第一语言没有对应资源匹配,可继续查找匹配第二位的语言,这就是语言列表的作用。如果列表中的语言都没匹配上,则使用默认资源。
特别注意点:简体中文与繁体中文不是同一体系的.
示例1:语言设置为简体中文,没有values-zh-rCN的资源,即使有values-zh-rTW或者values-zh-rHK的资源也不会使用,而会使用默认的资源。
示例2:语言设置为繁体中文,没有values-zh-rTW的资源,即使有values-zh或values-zh-rCN的资源也不会使用,而会使用默认资源。

参考:
Android多语言国际化适配(兼容7.0):https://blog.csdn.net/pigdreams/article/details/81277110
Android 7.0多语言支持开发浅析:https://blog.csdn.net/cekiasoo/article/details/53012646
保留指定语言:https://developer.android.com/studio/build/shrink-code