* fixed bugs

meow
Dominika Liberda 2021-12-20 16:02:01 +01:00
parent dfe6c493de
commit 3d8323e8ef
1 changed files with 17 additions and 15 deletions

32
main.py
View File

@ -14,12 +14,12 @@ headers = {"Authorization": "token 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",
"Accept": "application/json"}
user = "DomiOwO"
repo = "iwisoftware"
files=[{}]
files=[{}] # offsetting by 1 because FD 0 is invalid
files_buffers=[[]]
def getReleases():
if not releases:
a=requests.get("https://api.github.com/repos/"+ user +"/" + repo + "/releases", headers = headers);
a=requests.get("https://api.github.com/repos/"+ user + "/" + repo + "/releases", headers = headers);
x=a.json()
for i in x:
releases.extend([{"name":i["tag_name"], "id":i["id"]}])
@ -81,8 +81,7 @@ class Passthrough(Operations):
if full_path.split('/')[-1] in assets[full_path.split('/')[-2]]:
st_size = assets[full_path.split('/')[-2]][full_path.split('/')[-1]]["size"]
else:
st_mode = 0o100000
st_size = 0
raise FuseOSError(2)
else:
st_mode = 0o100000
st_size = 0
@ -142,21 +141,21 @@ class Passthrough(Operations):
if releases[i]["name"] == path.split("/")[1]:
a = requests.delete("https://api.github.com/repos/" + user + "/" + repo + "/releases/" + str(releases[i]["id"]),
headers = _h)
assets[releases[i]["name"]] = {}
del(assets[releases[i]["name"]])
del(releases[i])
print(a.content)
return 0
def mkdir(self, path, mode):
print("-- mkdir", path)
global releases
global releases, assets
a = requests.post("https://api.github.com/repos/" + user + "/" + repo + "/releases",
headers = headers,
data = '{"tag_name":"'+path.split("/")[1]+'"}')
print(a.content)
x = a.json()
releases+=[{"name":path.split("/")[1], "id": x["id"]}]
assets[path.split('/')[-2]]={}
releases.extend([{"name": path.split("/")[1], "id": x["id"]}])
assets[path.split('/')[1]] = {}
return 0
def statfs(self, path):
@ -204,6 +203,7 @@ class Passthrough(Operations):
def create(self, path, mode, fi=None):
print("-- create")
assets[path.split('/')[-2]][path.split('/')[-1]] = {"id": -1, "size": 0}
return allocateFd(path)
def read(self, path, length, offset, fh):
@ -222,9 +222,12 @@ class Passthrough(Operations):
_h["Range"] = "bytes=" + str(f["len"]) + "-" + str(f["len"] + fetch_len - 1)
f["len"] += fetch_len
_h["Accept"] = "application/octet-stream"
a = requests.get("https://api.github.com/repos/" + user + "/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]),
try:
a = requests.get("https://api.github.com/repos/" + user + "/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]),
headers = _h);
files_buffers[fh].append(bytes(a.content))
files_buffers[fh].append(bytes(a.content))
except:
raise FuseOSError(2) # idk, lets fix getattr sometime
return b''.join(files_buffers[fh])[offset:offset+length]
def write(self, path, buf, offset, fh):
@ -247,7 +250,7 @@ class Passthrough(Operations):
f = files[fh]
if(f["state"] == 1):
_h = headers
_h["Content-Type"] = "application/octet-stream"
_h["Content-Type"] = "application/json"
for i in releases: # move this into a function?
if i["name"] == path.split('/')[-2]:
id = i["id"]
@ -260,10 +263,9 @@ class Passthrough(Operations):
headers = _h)
print(a.content)
res = a.json()
print(assets[path.split('/')[-2]])
if not assets[path.split('/')[-2]]:
assets[path.split('/')[-2]]={}
print(assets[path.split('/')[-2]])
print(assets)
#if not assets[path.split('/')[-2]]:
# assets[path.split('/')[-2]] = [{}]
assets[path.split('/')[-2]][path.split('/')[-1]] = {"id": res["id"], "size": res["size"]}
del(files[fh]) # idk, bad syntax?
del(files_buffers[fh])