|
| 1 | +// Unix-style stat — OFSF record metadata (path or uuid) |
| 2 | +if args.len == 0 ( |
| 3 | + terminal.writeLine("usage: stat <path|uuid>") |
| 4 | + return |
| 5 | +) |
| 6 | + |
| 7 | +local target = args[1] |
| 8 | +local resolved = terminal.resolvePath(target) |
| 9 | +local ok = false |
| 10 | + |
| 11 | +// Try path, path.folder, then raw uuid / argument |
| 12 | +try ( |
| 13 | + file "open" resolved "onlyaccess" |
| 14 | + ok = true |
| 15 | +) catch e ( |
| 16 | + ok = false |
| 17 | +) |
| 18 | + |
| 19 | +if !ok ( |
| 20 | + try ( |
| 21 | + file "open" (resolved ++ ".folder") "onlyaccess" |
| 22 | + ok = true |
| 23 | + resolved = resolved ++ ".folder" |
| 24 | + ) catch e2 ( |
| 25 | + ok = false |
| 26 | + ) |
| 27 | +) |
| 28 | + |
| 29 | +if !ok ( |
| 30 | + try ( |
| 31 | + file "open" target "onlyaccess" |
| 32 | + ok = true |
| 33 | + resolved = target |
| 34 | + ) catch e3 ( |
| 35 | + ok = false |
| 36 | + ) |
| 37 | +) |
| 38 | + |
| 39 | +if !ok ( |
| 40 | + terminal.writeLine("stat: cannot stat '" ++ target ++ "': No such file or directory") |
| 41 | + return |
| 42 | +) |
| 43 | + |
| 44 | +// entryLabels: type name location data data2 x y id created edited icon size permissions uuid |
| 45 | +local typ = fileGet(1) |
| 46 | +local name = fileGet(2) |
| 47 | +local location = fileGet(3) |
| 48 | +local dataField = fileGet(4) |
| 49 | +local data2 = fileGet(5) |
| 50 | +local x = fileGet(6) |
| 51 | +local y = fileGet(7) |
| 52 | +local id = fileGet(8) |
| 53 | +local created = fileGet(9) |
| 54 | +local edited = fileGet(10) |
| 55 | +local icon = fileGet(11) |
| 56 | +local size = fileGet(12) |
| 57 | +local perms = fileGet(13) |
| 58 | +local uuid = fileGet(14) |
| 59 | +file "close" |
| 60 | + |
| 61 | +local fullName = name ++ typ |
| 62 | +local path = location ++ "/" ++ name ++ typ |
| 63 | +local dataPreview = dataField |
| 64 | + |
| 65 | +if typ == ".folder" ( |
| 66 | + fullName = name ++ "/" |
| 67 | + path = location ++ "/" ++ name |
| 68 | + try ( |
| 69 | + local kids = ("" ++ dataField).JsonParse() |
| 70 | + if typeof(kids) == "array" ( |
| 71 | + dataPreview = kids.len ++ " children" |
| 72 | + ) else ( |
| 73 | + dataPreview = "(folder)" |
| 74 | + ) |
| 75 | + ) catch e ( |
| 76 | + dataPreview = "(folder)" |
| 77 | + ) |
| 78 | +) else ( |
| 79 | + local raw = "" ++ dataField |
| 80 | + if raw.len > 80 ( |
| 81 | + dataPreview = raw.trim(1, 80) ++ "..." |
| 82 | + ) |
| 83 | +) |
| 84 | + |
| 85 | +local createdS = "" ++ created |
| 86 | +local editedS = "" ++ edited |
| 87 | +try ( |
| 88 | + eval ("globalThis.__statC = (function(){ try { const n = +" ++ ("" ++ created).JsonStringify() ++ "; return n ? new Date(n).toISOString() : String(n) } catch(e) { return " ++ ("" ++ created).JsonStringify() ++ " } })()") |
| 89 | + eval ("globalThis.__statE = (function(){ try { const n = +" ++ ("" ++ edited).JsonStringify() ++ "; return n ? new Date(n).toISOString() : String(n) } catch(e) { return " ++ ("" ++ edited).JsonStringify() ++ " } })()") |
| 90 | + createdS = __statC |
| 91 | + editedS = __statE |
| 92 | +) catch e ( |
| 93 | + // keep raw timestamps |
| 94 | +) |
| 95 | + |
| 96 | +local permsS = perms |
| 97 | +try ( |
| 98 | + if typeof(perms) == "array" or typeof(perms) == "object" ( |
| 99 | + permsS = perms.JsonStringify() |
| 100 | + ) |
| 101 | +) catch e ( |
| 102 | + permsS = "" ++ perms |
| 103 | +) |
| 104 | + |
| 105 | +terminal.writeLine(" File: " ++ fullName) |
| 106 | +terminal.writeLine(" Path: " ++ path) |
| 107 | +terminal.writeLine(" UUID: " ++ uuid) |
| 108 | +terminal.writeLine(" ID: " ++ id) |
| 109 | +terminal.writeLine(" Type: " ++ typ) |
| 110 | +terminal.writeLine(" Size: " ++ size) |
| 111 | +terminal.writeLine(" Data: " ++ dataPreview) |
| 112 | +terminal.writeLine("Access: " ++ permsS) |
| 113 | +terminal.writeLine("Create: " ++ createdS) |
| 114 | +terminal.writeLine("Modify: " ++ editedS) |
| 115 | +if icon != null and ("" ++ icon).len > 0 ( |
| 116 | + local ic = "" ++ icon |
| 117 | + if ic.len > 60 ( |
| 118 | + ic = ic.trim(1, 60) ++ "..." |
| 119 | + ) |
| 120 | + terminal.writeLine(" Icon: " ++ ic) |
| 121 | +) |
| 122 | +if data2 != null and data2 != 0 and data2 != "" ( |
| 123 | + terminal.writeLine(" Data2: " ++ data2) |
| 124 | +) |
| 125 | +terminal.writeLine(" Pos: " ++ x ++ ", " ++ y) |
0 commit comments