* buggy buffering, unlinking
This commit is contained in:
parent
940030ed7b
commit
5ae7b973de
46
main.py
46
main.py
|
@ -10,7 +10,8 @@ from fuse import FUSE, FuseOSError, Operations, fuse_get_context
|
|||
|
||||
releases = []
|
||||
assets = {}
|
||||
headers = {"Authorization":"token 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"}
|
||||
headers = {"Authorization": "token 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",
|
||||
"Accept": "application/json"}
|
||||
repo = "iwisoftware"
|
||||
files=[{"fd":0}]
|
||||
|
||||
|
@ -29,7 +30,11 @@ def getReleases():
|
|||
def allocateFd(path):
|
||||
global files
|
||||
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
|
||||
|
||||
def fileByFd(fd):
|
||||
|
@ -150,7 +155,11 @@ class Passthrough(Operations):
|
|||
|
||||
def unlink(self, path):
|
||||
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):
|
||||
print("-- symlink")
|
||||
|
@ -182,6 +191,7 @@ class Passthrough(Operations):
|
|||
|
||||
def read(self, path, length, offset, fh):
|
||||
f = fileByFd(fh)
|
||||
f["state"] = 0
|
||||
|
||||
print("-- read: offset ", offset, " len ", length, " path ", path)
|
||||
if offset + length > len(f["buffer"]):
|
||||
|
@ -196,17 +206,9 @@ class Passthrough(Operations):
|
|||
|
||||
def write(self, path, buf, offset, fh):
|
||||
print("-- write: offset ", offset, " buf ", buf, " path ", path)
|
||||
_h = headers
|
||||
_h["Content-Type"] = "application/octet-stream"
|
||||
for i in releases:
|
||||
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)
|
||||
f = fileByFd(fh)
|
||||
f["state"] = 1
|
||||
f["buffer"] += buf
|
||||
return 0
|
||||
|
||||
def truncate(self, path, length, fh=None):
|
||||
|
@ -219,6 +221,22 @@ class Passthrough(Operations):
|
|||
|
||||
def release(self, path, fh):
|
||||
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)])
|
||||
|
||||
def fsync(self, path, fdatasync, fh):
|
||||
|
|
Loading…
Reference in a new issue