GitHub API-如何确定文件是否实际上是符号链接? [英] GitHub API - How do I find out if a file is actually a symlink?

查看:47
本文介绍了GitHub API-如何确定文件是否实际上是符号链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过GitHub API查询符号链接时,如果符号链接指向文件而不是目录,则会得到不同的结果.后者表现得更好,因为它返回了"type":"symlink" 作为其JSON的一部分,而前者返回了"type":"file" .示例文件符号链接,示例目录符号链接.

When querying a symlink via the GitHub API, I get different results if the symlink points to a file as opposed to a directory. The latter is more well behaved in that it returns "type": "symlink" as part of its JSON, whereas the former returns "type": "file". Example file symlink, example directory symlink.

当符号链接将自己广告宣传为文件时,这非常令人困惑,因为获取其下载URL只是获取符号链接的目标,而不是文件内容.

It's very confusing when a symlink advertises itself as a file, as GET-ing its download URL will just get you the target of the symlink and not the file contents.

如何确定文件实际上是符号链接,而不是真实文件?

How do I tell if a file is actually a symlink, as opposed to a real file?

此外,为文件符号链接返回类型"file"的行为是否是一个彻头彻尾的错误?只是看起来不正确.

Also, is the behaviour of returning type "file" for file symlinks a downright bug? It just doesn't seem right.

推荐答案

不幸的是,答案是您不要".(使用API​​的当前状态)无法区分文件请求和符号链接.来自文档:

The answer is unfortunately "you don't". There is no way (with the API in its current state) to differentiate between a file request and a symlink. From the documentation:

如果请求的:path指向符号链接,并且符号链接的目标是存储库中的普通文件,则API会以文件的内容进行响应[...]

If the requested :path points to a symlink, and the symlink's target is a normal file in the repository, then the API responds with the content of the file [...]

否则,API会以一个对象来描述符号链接本身:

Otherwise, the API responds with an object describing the symlink itself:

我在GitHub支持下提出了这个问题,他们确认没有办法做到这一点.他们提出要向内部团队提出要求,但我想这不太可能得到解决.

I raised this with GitHub support and they confirmed there's no way to do this. They offered to raise it as a request with the internal teams, but I would imagine it's unlikely to get picked up.

一种解决方法(并非在所有情况下都适用)是通过 https://raw来请求文件.githubusercontent.com/,如果是真实文件,则将返回文件内容,如果是符号链接,则将仅返回文件路径.

One work around (that isn't suitable in all scenarios) is to request the file via https://raw.githubusercontent.com/ which will return either the file contents if it's a real file, or just the file path if it's a symlink.

这篇关于GitHub API-如何确定文件是否实际上是符号链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆