diff --git a/main.py b/main.py index 01a4713..2ee7ab7 100755 --- a/main.py +++ b/main.py @@ -12,10 +12,7 @@ releases = [] assets = {} headers = {"Authorization":"token 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"} repo = "owosoftware" -offset_temp = 0 # TODO -buffer_len = 0 # TODO -global buffer; -buffer = b"" +files=[{"fd":0}] def getReleases(): if not releases: @@ -28,7 +25,20 @@ def getReleases(): for j in i["assets"]: assets[i["tag_name"]][j["name"]]={"id": j["id"], "size": j["size"]} 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): def __init__(self, root): self.root = root @@ -81,7 +91,7 @@ class Passthrough(Operations): 'st_ctime': 1, 'st_gid': 1000, 'st_mode': int(st_mode), - 'st_mtime': 1625937692.4645624, + 'st_mtime': 1, 'st_nlink': 16, 'st_size': st_size, 'st_uid': 1000} @@ -164,61 +174,44 @@ class Passthrough(Operations): def open(self, path, flags): print("-- open") - full_path = self._full_path(path) - #return os.open(full_path, flags) - return random.randrange(1,100) # TODO + return allocateFd(path) def create(self, path, mode, fi=None): print("-- create") - #uid, gid, pid = fuse_get_context() - #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) + return allocateFd(path) def read(self, path, length, offset, fh): - global buffer - global buffer_len + f = fileByFd(fh) + print("-- read: offset ", offset, " len ", length, " path ", path) - if offset + length > buffer_len: - print("buffer exhausted: ", buffer_len) + if offset + length > len(f["buffer"]): + print("buffer exhausted: ", len(f["buffer"])) _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" 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 - buffer_len = buffer_len + 10485760 - #os.lseek(fh, offset, os.SEEK_SET) - #return os.read(fh, length) - return buffer[offset:offset+length] + f["buffer"] += a.content + return f["buffer"][offset:offset+length] def write(self, path, buf, offset, fh): print("-- write: offset ", offset, " buf ", buf, " path ", path) - #os.lseek(fh, offset, os.SEEK_SET) - #return os.write(fh, buf) return 0 def truncate(self, path, length, fh=None): print("-- truncate") - full_path = self._full_path(path) - #return random.randrange(1,100) return 0 - #with open(full_path, 'r+') as f: - # f.truncate(length) def flush(self, path, fh): print("-- flush") - #return os.fsync(fh) return 0 def release(self, path, fh): print("-- release/close") - _offset = 0 - #return os.close(fh) + del(files[fileByFd(fh)]) def fsync(self, path, fdatasync, fh): print("-- fsync") - return self.flush(path, fh) + return 0 def main(mountpoint):