This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sir_Mr_Bman's profile picture

What am I doing wrong here?

Started by Sir_Mr_Bman, 25 April 2014 - 01:07 PM
Sir_Mr_Bman #1
Posted 25 April 2014 - 03:07 PM
So, I've made an installer that pulls files from my github.

What am I doing wrong here? It's not working, regardless of what I try.


-- GitGET Function
--
-- Written for Sir_Mr_Bmans GitHub
local function gitGet(file, save)
if fs.exists("/dwnlds") then
  fs.delete("/dwnlds")
end
fs.makeDir("/dwnlds")
term.setTextColor(colors.purple)
print("[GitGET] Getting file: "..file)
local response = http.get(
  "https://raw.githubusercontent.com/Sir-Mr-Bman/IndustrialSecurity/master/src/"..textutils.urlEncode(file)..".lua"	
)
if response then
  print("[GitGET] Server responded. Downloading...")
  local save = response.readAll()
  response.close()
  local h = fs.open("/dwnlds/"..save, "w")
  h.write(save)
  h.close()
  print("[GitGET] File downloaded.")
else
  print("[GitGET] Server did not respond. Is it offline?")
  print("[GitGET] Check your internet connection, and firewall settings.")
end
end

Any help is welcomed.

EDIT: Updated code.
EDIT: Fixed code spacing.
Edited on 25 April 2014 - 01:16 PM
viluon #2
Posted 25 April 2014 - 03:22 PM
What kind of error are you getting? Is this all the code? I don't see any function call (gitGet(sth,sth))
Edited on 25 April 2014 - 01:29 PM
Lyqyd #3
Posted 25 April 2014 - 03:23 PM
What does it do that indicates "not working" to you? What does the script print out? Does it throw any errors?
Sir_Mr_Bman #4
Posted 25 April 2014 - 03:32 PM
It doesn't throw any errors, it just doesn't download as it should. Also, I've only included the FUNCTION, not the entire program.

Thanks for the quick responses!
viluon #5
Posted 25 April 2014 - 03:41 PM
Eh, fine.. Then please post the entire program so we can see what's wrong there.. Moreover, you haven't answered my question: what's the error? or output? what changes in the filesystem can you see? what CC version are you using? is it 1.63? Did you whitelist github in your ComputerCraft.cfg? Please be specific.

"it just doesn't download as it should" That's not how an error report should look like.

1) What is 'should' here? What do you want your program to do?
2) What does it mean "it just doesn't download"? Does it mean the download isn't even started? did you try catching http_failure or http_success events?
3) What output can you see on the screen? Does the program write something? If yes, at which stage does it stop?
Edited on 25 April 2014 - 01:47 PM
Sir_Mr_Bman #6
Posted 25 April 2014 - 07:45 PM
Sorry.
Here is a link to my entire program:

http://pastebin.com/ikFxj3Av

What happens is this:

When you run the program, it makes the first call to the "gitGet" method. This works as it should, at first.
The logger then says that it is attempting to connect to github.
The logger then replies and says that there was no response from github, and it attempts to go and try the next file.
The filesystem has not changed at all, other than creating the "dwnlds" file.
viluon #7
Posted 25 April 2014 - 07:49 PM
And there's nothing inside that file? (Looking at your code)

Edit:oh sorry its a directory I see

What version of CC do you use? (I'm on an Android device, cannot try the code now)

Edit2:don't be sorry, it's totally okay, just remember this next time ;)/>
Edited on 25 April 2014 - 05:53 PM
Sir_Mr_Bman #8
Posted 26 April 2014 - 06:28 PM
It wasn't working for me at all… Humph.
Lyqyd #9
Posted 26 April 2014 - 06:33 PM
Are you on CC 1.63? Have you tried having it print out the final url it is using? Have you gone to that url in your browser to verify that it works?