1
0
mirror of https://github.com/natnat-mc/moonbuild synced 2026-05-28 21:09:40 +02:00
Files
moonbuild/moonbuild/_fs/cmd.moon
T
Codinget c8670ab903 v2
2020-11-07 21:01:26 +01:00

55 lines
1.5 KiB
MoonScript

import escape from require 'moonbuild._cmd'
import execute from require 'moonbuild.compat.execute'
import popen from io
import gmatch, match, sub from string
error "commands ls and stat aren't available" unless (execute "which ls >/dev/null 2>&1") and (execute "which stat >/dev/null 2>&1")
{
dir: (path) ->
[file for file in (popen "ls -1 #{escape path}")\lines!]
attributes: (path) ->
fd = popen "stat -c '%d %i %A %h %u %g %s %b %t %T %X %Y %Z' #{escape path}"
stat = [part for part in gmatch (fd\read '*a'), "%S+"]
fd\close!
fd = popen "stat -f -c '%S' #{escape path}"
blksize = match (fd\read '*a'), '%S+'
fd\close!
{
dev: tonumber stat[1]
ino: tonumber stat[2]
nlink: tonumber stat[4]
uid: tonumber stat[5]
gid: tonumber stat[6]
size: tonumber stat[7]
blocks: tonumber stat[8]
blksize: tonumber blksize
access: tonumber stat[11]
modification: tonumber stat[12]
change: tonumber stat[13]
permissions: do
sub stat[3], 2
mode: do
switch sub stat[3], 1, 1
when '-' then 'file'
when 'd' then 'directory'
when 'l' then 'link'
when 's' then 'socket'
when 'p' then 'named pipe'
when 'c' then 'char device'
when 'b' then 'block device'
else 'other'
rdev: do
(tonumber stat[9]) * 256 + (tonumber stat[10])
}
mkdir: (path) ->
error "Mkdir #{path} failed" unless execute "mkdir #{escape path}"
}