* multiple fds
parent
5ef61aad02
commit
b193967e50
61
main.py
61
main.py
|
@ -12,10 +12,7 @@ releases = []
|
||||||
assets = {}
|
assets = {}
|
||||||
headers = {"Authorization":"token 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"}
|
headers = {"Authorization":"token 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"}
|
||||||
repo = "owosoftware"
|
repo = "owosoftware"
|
||||||
offset_temp = 0 # TODO
|
files=[{"fd":0}]
|
||||||
buffer_len = 0 # TODO
|
|
||||||
global buffer;
|
|
||||||
buffer = b""
|
|
||||||
|
|
||||||
def getReleases():
|
def getReleases():
|
||||||
if not releases:
|
if not releases:
|
||||||
|
@ -28,7 +25,20 @@ def getReleases():
|
||||||
for j in i["assets"]:
|
for j in i["assets"]:
|
||||||
assets[i["tag_name"]][j["name"]]={"id": j["id"], "size": j["size"]}
|
assets[i["tag_name"]][j["name"]]={"id": j["id"], "size": j["size"]}
|
||||||
print(assets)
|
print(assets)
|
||||||
|
|
||||||
|
def allocateFd(path):
|
||||||
|
global files
|
||||||
|
fd = files[-1]["fd"] + 1
|
||||||
|
files += [{"fd": fd, "path": path, "buffer": b""}]
|
||||||
|
return fd
|
||||||
|
|
||||||
|
def fileByFd(fd):
|
||||||
|
global files
|
||||||
|
for i in files:
|
||||||
|
if i["fd"] == fd:
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
|
|
||||||
class Passthrough(Operations):
|
class Passthrough(Operations):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
|
@ -81,7 +91,7 @@ class Passthrough(Operations):
|
||||||
'st_ctime': 1,
|
'st_ctime': 1,
|
||||||
'st_gid': 1000,
|
'st_gid': 1000,
|
||||||
'st_mode': int(st_mode),
|
'st_mode': int(st_mode),
|
||||||
'st_mtime': 1625937692.4645624,
|
'st_mtime': 1,
|
||||||
'st_nlink': 16,
|
'st_nlink': 16,
|
||||||
'st_size': st_size,
|
'st_size': st_size,
|
||||||
'st_uid': 1000}
|
'st_uid': 1000}
|
||||||
|
@ -164,61 +174,44 @@ class Passthrough(Operations):
|
||||||
|
|
||||||
def open(self, path, flags):
|
def open(self, path, flags):
|
||||||
print("-- open")
|
print("-- open")
|
||||||
full_path = self._full_path(path)
|
return allocateFd(path)
|
||||||
#return os.open(full_path, flags)
|
|
||||||
return random.randrange(1,100) # TODO
|
|
||||||
|
|
||||||
def create(self, path, mode, fi=None):
|
def create(self, path, mode, fi=None):
|
||||||
print("-- create")
|
print("-- create")
|
||||||
#uid, gid, pid = fuse_get_context()
|
return allocateFd(path)
|
||||||
#full_path = self._full_path(path)
|
|
||||||
#fd = os.open(full_path, os.O_WRONLY | os.O_CREAT, mode)
|
|
||||||
#os.chown(full_path,uid,gid) #chown to context uid & gid
|
|
||||||
return random.randrange(1,100)
|
|
||||||
|
|
||||||
def read(self, path, length, offset, fh):
|
def read(self, path, length, offset, fh):
|
||||||
global buffer
|
f = fileByFd(fh)
|
||||||
global buffer_len
|
|
||||||
print("-- read: offset ", offset, " len ", length, " path ", path)
|
print("-- read: offset ", offset, " len ", length, " path ", path)
|
||||||
if offset + length > buffer_len:
|
if offset + length > len(f["buffer"]):
|
||||||
print("buffer exhausted: ", buffer_len)
|
print("buffer exhausted: ", len(f["buffer"]))
|
||||||
_h = headers
|
_h = headers
|
||||||
_h["Range"] = "bytes=" + str(buffer_len) + "-" + str(buffer_len + 10485760) # 5MB
|
_h["Range"] = "bytes=" + str(len(f["buffer"])) + "-" + str(len(f["buffer"]) + 10485760) # 5MB
|
||||||
_h["Accept"] = "application/octet-stream"
|
_h["Accept"] = "application/octet-stream"
|
||||||
a = requests.get("https://api.github.com/repos/DomiOwO/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]), headers=headers);
|
a = requests.get("https://api.github.com/repos/DomiOwO/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]), headers=headers);
|
||||||
buffer += a.content
|
f["buffer"] += a.content
|
||||||
buffer_len = buffer_len + 10485760
|
return f["buffer"][offset:offset+length]
|
||||||
#os.lseek(fh, offset, os.SEEK_SET)
|
|
||||||
#return os.read(fh, length)
|
|
||||||
return buffer[offset:offset+length]
|
|
||||||
|
|
||||||
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)
|
||||||
#os.lseek(fh, offset, os.SEEK_SET)
|
|
||||||
#return os.write(fh, buf)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def truncate(self, path, length, fh=None):
|
def truncate(self, path, length, fh=None):
|
||||||
print("-- truncate")
|
print("-- truncate")
|
||||||
full_path = self._full_path(path)
|
|
||||||
#return random.randrange(1,100)
|
|
||||||
return 0
|
return 0
|
||||||
#with open(full_path, 'r+') as f:
|
|
||||||
# f.truncate(length)
|
|
||||||
|
|
||||||
def flush(self, path, fh):
|
def flush(self, path, fh):
|
||||||
print("-- flush")
|
print("-- flush")
|
||||||
#return os.fsync(fh)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def release(self, path, fh):
|
def release(self, path, fh):
|
||||||
print("-- release/close")
|
print("-- release/close")
|
||||||
_offset = 0
|
del(files[fileByFd(fh)])
|
||||||
#return os.close(fh)
|
|
||||||
|
|
||||||
def fsync(self, path, fdatasync, fh):
|
def fsync(self, path, fdatasync, fh):
|
||||||
print("-- fsync")
|
print("-- fsync")
|
||||||
return self.flush(path, fh)
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def main(mountpoint):
|
def main(mountpoint):
|
||||||
|
|
Loading…
Reference in New Issue