Jump to content




Github SHA Key


  • You cannot reply to this topic
6 replies to this topic

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 14 May 2015 - 06:18 PM

So I've been messing around with github's API to create an installer / updater, and I found this:

https://developer.gi...s/#get-contents

Which has been very helpful so far. I can now easily download everything in a repo, but I'm wanting to check a file before downloading, to see if it is already the latest version.

I think I can use the sha key to do this somehow, but I'm not sure how. I heard on IRC you can, but they could be mistaken. From Stack Overflow I got that it's the hash of the blob, but I don't know what a blob is or how I could check against it.

{
  "type": "file",
  "encoding": "base64",
  "size": 5362,
  "name": "README.md",
  "path": "README.md",
  "content": "encoded content ...",
  "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", --#this
  "url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
  "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
  "html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
  "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
  "_links": {
    "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
    "self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
    "html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
  }
}


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 14 May 2015 - 06:54 PM

I use the sha github provides for each file in Packman. I end up just storing the sha from the last time the file was downloaded to compare against the results returned by github in the future. Reading a string out of a file is much less computationally intensive than trying to calculate the hash again!

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 14 May 2015 - 08:44 PM

That's what I was thinking of doing. Thanks!

Would it be worth storing it as a comment on top of the program, vs in a separate file? Or rather, is there any difference in speed reading the first line of a 1000 line file vs 1 line file?

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 14 May 2015 - 10:03 PM

The one line file would likely be marginally quicker, but I'm not sure how much of a difference it would make in practical terms--you're also using data from a website. With Packman, I store the sha hashes for each file in a single file per installed package, which may be wise to do if you're going to be using this technique to keep multiple files up to date. An "installed-versions" file or similar such would do it.

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 14 May 2015 - 11:25 PM

I thought about creating a new topic, but this thread "inspired" the code I wrote so...

I'm having troubles.

Spoiler

The code works perfectly without the last three lines, however when they are added this line:
local file = fs.open( "installed" )
errors with
Expected string, string
Which I find really, really aggravating. Obviously fs.open does not expect two strings. Neither does file.write, nor textutils.serialize. Yet without those lines, no errors occur.

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 14 May 2015 - 11:55 PM

Well, actually, fs.open does expect two strings. How else would it know whether you want the file opened in read mode, write mode, append mode, or one of their binary counterpart modes? It appears that you may want to use "w", for write mode, for the second argument.

#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 15 May 2015 - 12:02 AM

Did I really?.. Oh I did .. *hides under a rock*





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users