LDDestroier

fs sandbox test

Dec 1st, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. makeFS = function(root)
  2.     root = root or ""
  3.    
  4.     local ciw = function(dir) --'check if within' the root directory
  5.         if fs.isReadOnly(dir) then
  6.             return true
  7.         else
  8.             return string.find("///"..dir, "///"..root) and true or false
  9.         end
  10.     end
  11.    
  12.     local nonexistdir = function()
  13.         local number
  14.         while true do
  15.             for a = 1, 512 do
  16.                 thedir = "dir"..tostring(math.random(1,9999999999999))
  17.                 if not fs.exists(thedir) then
  18.                     return thedir
  19.                 end
  20.             end
  21.             sleep(0)
  22.         end
  23.     end
  24.    
  25.     local nfs = {}
  26.     nfs.combine = fs.combine
  27.     nfs.getDrive = function(dir)
  28.         if not ciw(dir) then dir = nonexistdir() end
  29.         return fs.getDrive(dir)
  30.     end
  31.     nfs.getName = function(dir)
  32.         if not ciw(dir) then dir = nonexistdir() end
  33.         return fs.getName(dir)
  34.     end
  35.     nfs.getFreeSpace = function(dir)
  36.         if not ciw(dir) then dir = nonexistdir() end
  37.         return fs.getFreeSpace(dir and nfs.combine(root,dir) or nil)
  38.     end
  39.     nfs.getSize = function(dir)
  40.         if not ciw(dir) then dir = nonexistdir() end
  41.         return fs.getSize(nfs.combine(root,dir))
  42.     end
  43.     nfs.list = function(dir)
  44.         if not ciw(dir) then dir = nonexistdir() end
  45.         return fs.list(nfs.combine(root,dir))
  46.     end
  47.     nfs.exists = function(dir)
  48.         if not ciw(dir) then dir = nonexistdir() end
  49.         return fs.exists(nfs.combine(root,dir))
  50.     end
  51.     nfs.isDir = function(dir)
  52.         if not ciw(dir) then dir = nonexistdir() end
  53.         return fs.isDir(nfs.combine(root,dir))
  54.     end
  55.     nfs.isReadOnly = function(dir)
  56.         if not ciw(dir) then dir = nonexistdir() end
  57.         return fs.isReadOnly(nfs.combine(root,dir))
  58.     end
  59.     nfs.makeDir = function(dir)
  60.         if not ciw(dir) then dir = nonexistdir() end
  61.         return fs.makeDir(nfs.combine(root,dir))
  62.     end
  63.     nfs.move = function(from,to)
  64.         if not ciw(from) then from = nonexistdir() end
  65.         if not ciw(to) then to = nonexistdir() end
  66.         return fs.move(nfs.combine(root,from),nfs.combine(root,to))
  67.     end
  68.     nfs.copy = function(from,to)
  69.         if not ciw(from) then from = nonexistdir() end
  70.         if not ciw(to) then to = nonexistdir() end
  71.         return fs.copy(nfs.combine(root,from),nfs.combine(root,to))
  72.     end
  73.     nfs.delete = function(dir)
  74.         if not ciw(dir) then dir = nonexistdir() end
  75.         return fs.delete(nfs.combine(root,dir))
  76.     end
  77.     nfs.open = function(file,mode)
  78.         if not ciw(file) then file = nonexistdir() end
  79.         return fs.open(nfs.combine(root,file),mode)
  80.     end
  81.     nfs.find = function(dir)
  82.         if not ciw(dir) then dir = nonexistdir() end
  83.         return fs.find(dir and nfs.combine(root,dir) or nil)
  84.     end
  85.     nfs.getDir = function(dir)
  86.         if not ciw(dir) then dir = nonexistdir() end
  87.         return fs.getDir(nfs.combine(root,dir))
  88.     end
  89.     nfs.complete = function(name,path,inclFiles,inclSlashes)
  90.         if not ciw(path) then path = nonexistdir() end
  91.         return fs.complete(name,nfs.combine(root,path),inclFiles,inclSlashes)
  92.     end
  93.  
  94.     return nfs
  95. end
Add Comment
Please, Sign In to add comment