Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file utility to check if files are binary #2615

Merged
merged 3 commits into from
Oct 12, 2020
Merged

Conversation

jurre
Copy link
Member

@jurre jurre commented Oct 8, 2020

Noticed a bunch of extensions that were incorrectly being submitted as
binary to the GitHub API.

Detecting if files are binary or not is hard, and lists of extensions are a pain to maintain, plus there can be any number of files that don't have an extension. This is especially problematic for git dependencies.

Currently, when a file is not marked correctly as binary, this causes issues with PR creation, as we need to encode and upload those files differently

This 🩹 should at least make sure that we do the right thing.

Longer term, we want to investigate creating compressed git packs, and uploading those packs using the API.

@jurre jurre requested a review from a team as a code owner October 8, 2020 16:19
@jurre jurre changed the title Add filenames and extensions that should not be binary Use file utility to check if files are binary Oct 8, 2020
@jurre
Copy link
Member Author

jurre commented Oct 8, 2020

I will add some tests to demonstrate pathological cases tomorrow, but would love other feedback in the meanwhile.

Copy link
Contributor

@jasonrudolph jasonrudolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add some tests to demonstrate pathological cases tomorrow, but would love other feedback in the meanwhile.

An additional test or two would be great, but regardless, this seems like a nice pragmatic choice. ⚡

@jurre jurre force-pushed the jurre/add-extensions branch 2 times, most recently from 67d9529 to 61963a4 Compare October 8, 2020 20:33
@jurre
Copy link
Member Author

jurre commented Oct 9, 2020

These cargo failures seem unrelated and I'm also getting them on main. Looking into it now

jurre added 3 commits October 12, 2020 13:52
Noticed a bunch of extensions that were incorrectly being submitted as
binary to the GitHub API.

Alternatively we could also invert this and list a few known binary
extensions, for example:

```ruby
BINARY_EXTS = %w(
  .gem
  .zip
  .tar
  .gz
  .tgz
  .wav
  .rar
  .mp3
)
```

This has the downside that any binary files without an extension are
not picked up. However, we have that same problem currently with text
files. I already spotted some `bin/whatever` files that should not be
submitted as binary to the GH API.
The `.bundlecache` file is an empty file that bundler puts in a git
dependencies `vendor/cache/<gem>` folder, to indicate that the file does
not need to be re-downloaded, see:

https://github.com/rubygems/bundler/blob/6394536271a0326efd4ed3544b78e528da7e90b1/lib/bundler/plugin/api/source.rb#L175-L192

Empty files without an extension are treated as binary files by the
`file` util. This is not problematic for submitting to the GitHub API,
since it ends up simply base64 encoding (and subsequently decoding in
GitHub) an empty string.
@jurre jurre force-pushed the jurre/add-extensions branch from 3db52f4 to 5282864 Compare October 12, 2020 11:52
@jurre jurre merged commit 38ab54c into main Oct 12, 2020
@jurre jurre deleted the jurre/add-extensions branch October 12, 2020 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants