Installer import into contrib (real import this time)
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / lua / scripts / test / filesystem.lua
1 -- filesystem.lua
2 -- $Id: filesystem.lua,v 1.10 2005/03/27 07:21:08 cpressey Exp $
3 -- Test of dfuibe_lua's filesystem functionalities.
4
5 App = require "app"; App.init()
6 require "mountpoint"
7
8 local booltab = { [false] = "NO", [true] = "YES" }
9
10 App.start{
11     name = "FileSystem/MountPoints test program",
12     logfile = "filesystem.log"
13 }
14
15 files = FileSystem.dir("/etc")
16 for file in files do
17         local fullfile = "/etc/" .. files[file]
18         local string = fullfile .. "..." ..
19             "  is file? " .. booltab[FileSystem.is_file(fullfile)] ..
20             "  is dir? " .. booltab[FileSystem.is_dir(fullfile)] ..
21             "  is program? " .. booltab[FileSystem.is_program(fullfile)] ..
22             "  size=" .. tostring(FileSystem.size_of(fullfile))
23         print(string)
24 end
25
26 path = "/x/y/z"
27 print("basename of " .. path .. " is " .. FileSystem.basename(path))
28 print("dirname of  " .. path .. " is " .. FileSystem.dirname(path))
29
30 local fh, fname = FileSystem.mkstemp("/tmp/tmp.XXXXXX")
31 fh:write("hello!\n")
32 fh:close()
33 print("Wrote hello! to " .. fname)
34
35 local fs_descs = MountPoints.enumerate()
36 local i, fs_desc
37 for i, fs_desc in fs_descs do
38         print(
39             "mountpoint=", fs_desc.mountpoint,
40             "device=", fs_desc.device,
41             "type=", fs_desc.type
42         )
43 end
44
45 App.stop()