Refactored the entire code.

This commit is contained in:
2025-11-26 23:36:52 +03:00
parent 4709e81b81
commit 684d584402
3 changed files with 122 additions and 90 deletions

View File

@@ -3,40 +3,43 @@
module Octal = Octal
module Tar = Tar
let clean_path path =
let clean_split = List.filter (fun x -> (not (String.equal x "")) && (not (String.equal x "."))) in
clean_split (String.split_on_char '/' (String.trim path))
let (root, tar_ch) = Tar.parse_tar "asd.tar"
let () = Tar.print_tree "" root
let getattr path =
match Tar.find_from_split (clean_path path) root with
match Tar.find path root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "hi1", "hi1"))
| Some (File (_, md)) -> md
| Some (Directory (_, md)) -> md
| Some (InferredDirectory (_, md)) -> md
let readdir path _ =
match Tar.find_from_split (clean_path path) root with
match Tar.find path root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "234", "234"))
| Some (File (_, _)) -> raise (Unix.Unix_error (Unix.ENOENT, "345", "345"))
| Some (InferredDirectory (children, _))
| Some (Directory (children, _)) ->
["."; ".."] @ (List.map (fun (name, _) -> name) (Tar.NameMap.to_list children))
let read path buf offset amount =
match Tar.find_from_split (clean_path path) root with
(* There seems to be a bug here - the amount argument given to this function
is NOT the correct requested amount. The buffer size is correct though
so I'm taking that as the source of truth.
*)
let read path buf offset _amount =
(*
let () = Printf.printf "PARAMS %d %d %d\n" (Int64.to_int offset) amount (Bigarray.Array1.dim buf) in
let () = Out_channel.flush_all () in*)
match Tar.find path root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "read", path))
| Some (File (fo, md)) ->
(let (file_buf,read) = (Tar.read_file (File (fo, md)) tar_ch offset amount) in
(let (file_buf,read) = (Tar.read_file (File (fo, md)) tar_ch offset (Bigarray.Array1.dim buf)) in
Bytes.iteri (fun i c -> Bigarray.Array1.set buf i c) file_buf;
read)
| _ -> raise (Unix.Unix_error (Unix.EISDIR, "read", path))
let _ =
let () = Printf.printf "hmmm?\n" in
let () = List.iter (fun x -> Printf.printf "%s\n" x) (readdir "bin" 5) in
let () = Out_channel.flush_all () in
Fuse.main Sys.argv
{
Fuse.default_operations with