* buggy buffering, unlinking
parent
940030ed7b
commit
5ae7b973de
48
main.py
48
main.py
|
@ -10,13 +10,14 @@ from fuse import FUSE, FuseOSError, Operations, fuse_get_context
|
||||||
|
|
||||||
releases = []
|
releases = []
|
||||||
assets = {}
|
assets = {}
|
||||||
headers = {"Authorization":"token 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"}
|
headers = {"Authorization": "token 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",
|
||||||
|
"Accept": "application/json"}
|
||||||
repo = "iwisoftware"
|
repo = "iwisoftware"
|
||||||
files=[{"fd":0}]
|
files=[{"fd":0}]
|
||||||
|
|
||||||
def getReleases():
|
def getReleases():
|
||||||
if not releases:
|
if not releases:
|
||||||
a=requests.get("https://api.github.com/repos/DomiOwO/" + repo + "/releases", headers=headers);
|
a=requests.get("https://api.github.com/repos/DomiOwO/" + repo + "/releases", headers = headers);
|
||||||
x=a.json()
|
x=a.json()
|
||||||
for i in x:
|
for i in x:
|
||||||
releases.extend([{"name":i["tag_name"], "id":i["id"]}])
|
releases.extend([{"name":i["tag_name"], "id":i["id"]}])
|
||||||
|
@ -29,7 +30,11 @@ def getReleases():
|
||||||
def allocateFd(path):
|
def allocateFd(path):
|
||||||
global files
|
global files
|
||||||
fd = files[-1]["fd"] + 1
|
fd = files[-1]["fd"] + 1
|
||||||
files += [{"fd": fd, "path": path, "buffer": b""}]
|
files += [{"fd": fd,
|
||||||
|
"path": path,
|
||||||
|
"buffer": b"",
|
||||||
|
"state": None # 0 - read, 1 - write
|
||||||
|
}]
|
||||||
return fd
|
return fd
|
||||||
|
|
||||||
def fileByFd(fd):
|
def fileByFd(fd):
|
||||||
|
@ -150,7 +155,11 @@ class Passthrough(Operations):
|
||||||
|
|
||||||
def unlink(self, path):
|
def unlink(self, path):
|
||||||
print("-- unlink")
|
print("-- unlink")
|
||||||
return os.unlink(self._full_path(path))
|
global assets
|
||||||
|
a = requests.delete("https://api.github.com/repos/DomiOwO/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]),
|
||||||
|
headers = headers)
|
||||||
|
print(a.content)
|
||||||
|
return 0
|
||||||
|
|
||||||
def symlink(self, name, target):
|
def symlink(self, name, target):
|
||||||
print("-- symlink")
|
print("-- symlink")
|
||||||
|
@ -182,6 +191,7 @@ class Passthrough(Operations):
|
||||||
|
|
||||||
def read(self, path, length, offset, fh):
|
def read(self, path, length, offset, fh):
|
||||||
f = fileByFd(fh)
|
f = fileByFd(fh)
|
||||||
|
f["state"] = 0
|
||||||
|
|
||||||
print("-- read: offset ", offset, " len ", length, " path ", path)
|
print("-- read: offset ", offset, " len ", length, " path ", path)
|
||||||
if offset + length > len(f["buffer"]):
|
if offset + length > len(f["buffer"]):
|
||||||
|
@ -196,17 +206,9 @@ class Passthrough(Operations):
|
||||||
|
|
||||||
def write(self, path, buf, offset, fh):
|
def write(self, path, buf, offset, fh):
|
||||||
print("-- write: offset ", offset, " buf ", buf, " path ", path)
|
print("-- write: offset ", offset, " buf ", buf, " path ", path)
|
||||||
_h = headers
|
f = fileByFd(fh)
|
||||||
_h["Content-Type"] = "application/octet-stream"
|
f["state"] = 1
|
||||||
for i in releases:
|
f["buffer"] += buf
|
||||||
if i["name"] == path.split('/')[-2]:
|
|
||||||
id = i["id"]
|
|
||||||
break
|
|
||||||
|
|
||||||
a = requests.post("https://uploads.github.com/repos/DomiOwO/" + repo + "/releases/" + str(id) + "/assets?name=" + path.split('/')[-1],
|
|
||||||
data = buf,
|
|
||||||
headers = _h)
|
|
||||||
print(a.content)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def truncate(self, path, length, fh=None):
|
def truncate(self, path, length, fh=None):
|
||||||
|
@ -219,6 +221,22 @@ class Passthrough(Operations):
|
||||||
|
|
||||||
def release(self, path, fh):
|
def release(self, path, fh):
|
||||||
print("-- release/close")
|
print("-- release/close")
|
||||||
|
f = fileByFd(fh)
|
||||||
|
if(f["state"] == 1):
|
||||||
|
_h = headers
|
||||||
|
_h["Content-Type"] = "application/octet-stream"
|
||||||
|
for i in releases: # move this into a function?
|
||||||
|
if i["name"] == path.split('/')[-2]:
|
||||||
|
id = i["id"]
|
||||||
|
break
|
||||||
|
|
||||||
|
a = requests.post(
|
||||||
|
"https://uploads.github.com/repos/DomiOwO/" + repo + "/releases/" + str(id) + "/assets?name=" +
|
||||||
|
path.split('/')[-1],
|
||||||
|
data = f["buffer"],
|
||||||
|
headers = _h)
|
||||||
|
print(a.content)
|
||||||
|
|
||||||
#del(files[fileByFd(fh)])
|
#del(files[fileByFd(fh)])
|
||||||
|
|
||||||
def fsync(self, path, fdatasync, fh):
|
def fsync(self, path, fdatasync, fh):
|
||||||
|
|
Loading…
Reference in New Issue