2020-10-12 19:15:36 +11:00
|
|
|
local computer = require "computer"
|
2020-10-12 18:09:06 +11:00
|
|
|
local fs = require "filesystem"
|
|
|
|
local rpc = require "rpc"
|
|
|
|
local tA = {...}
|
|
|
|
local rpath, lpath = tA[1], tA[2], tA[3]
|
|
|
|
|
|
|
|
if #tA < 2 then
|
|
|
|
print("Usage: importfs <remote path> <local path>")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local function parsePath(path)
|
|
|
|
return path:match("(.+):(.+)")
|
|
|
|
end
|
|
|
|
|
|
|
|
local host, saddr = parsePath(rpath)
|
|
|
|
local px = rpc.proxy(host,"fs_"..saddr.."_")
|
|
|
|
local mc = 0
|
|
|
|
for k,v in pairs(px) do
|
|
|
|
mc = mc + 1
|
|
|
|
end
|
|
|
|
if mc < 1 then
|
2020-10-12 19:15:36 +11:00
|
|
|
error("no such remote filesystem: "..rpath)
|
2020-10-12 18:09:06 +11:00
|
|
|
end
|
2020-10-12 19:15:36 +11:00
|
|
|
local statcache = {}
|
2020-10-12 18:09:06 +11:00
|
|
|
px.address = rpath
|
2020-10-12 19:15:36 +11:00
|
|
|
if px.dirstat then -- use single call for file info
|
|
|
|
function px.list(path)
|
|
|
|
local t,e = px.dirstat(path)
|
|
|
|
if not t then return nil,e end
|
|
|
|
local rt = {}
|
|
|
|
for k,v in pairs(t) do
|
|
|
|
rt[#rt+1] = k
|
|
|
|
statcache[fs.canonical("/"..path.."/"..k)] = {computer.uptime(),v[1],v[2],v[3]}
|
|
|
|
end
|
|
|
|
return rt
|
|
|
|
end
|
|
|
|
local oid, osize, olm = px.isDirectory, px.size, px.lastModified
|
2020-10-12 19:20:22 +11:00
|
|
|
local function gce(p,n)
|
2020-10-12 19:15:36 +11:00
|
|
|
for k,v in pairs(statcache) do
|
|
|
|
if computer.uptime() > v[1] + 1 then
|
|
|
|
statcache[k] = nil
|
|
|
|
end
|
|
|
|
end
|
2020-10-12 19:20:22 +11:00
|
|
|
local ci = statcache["/"..fs.canonical(p)]
|
2020-10-12 19:15:36 +11:00
|
|
|
if ci then
|
2020-10-14 17:20:12 +11:00
|
|
|
return ci[n]
|
2020-10-12 19:15:36 +11:00
|
|
|
end
|
2020-10-12 19:20:22 +11:00
|
|
|
end
|
|
|
|
function px.isDirectory(path)
|
|
|
|
return gce(path, 2) or oid(path)
|
2020-10-12 19:15:36 +11:00
|
|
|
end
|
|
|
|
function px.size(path)
|
2020-10-12 19:20:22 +11:00
|
|
|
return gce(path, 3) or osize(path)
|
2020-10-12 19:15:36 +11:00
|
|
|
end
|
|
|
|
function px.lastModified(path)
|
2020-10-12 19:20:22 +11:00
|
|
|
return gce(path, 4) or olm(path)
|
2020-10-12 19:15:36 +11:00
|
|
|
end
|
|
|
|
end
|
2020-10-17 18:50:30 +11:00
|
|
|
local iro,e = px.isReadOnly()
|
|
|
|
if not iro then
|
|
|
|
error(e)
|
|
|
|
end
|
2020-10-14 17:20:12 +11:00
|
|
|
function px.isReadOnly()
|
|
|
|
return iro
|
|
|
|
end
|
2020-10-12 18:09:06 +11:00
|
|
|
fs.mount(px, lpath)
|