@@ -14,11 +14,11 @@ module Node.FS.Perms
1414
1515import Prelude
1616import Global (readInt )
17- import Data.Maybe (Maybe (..), isNothing )
18- import Data.Maybe.Unsafe (fromJust )
17+ import Data.Maybe (Maybe (..), isNothing , fromJust )
1918import Data.Char (fromCharCode )
2019import Data.String (toCharArray , joinWith , drop , charAt , indexOf )
2120import Data.Int (fromNumber )
21+ import Partial.Unsafe (unsafePartial )
2222
2323-- | A `Perm` value specifies what is allowed to be done with a particular
2424-- | file by a particular class of user — that is, whether it is
@@ -37,17 +37,17 @@ import Data.Int (fromNumber)
3737newtype Perm = Perm { r :: Boolean , w :: Boolean , x :: Boolean }
3838
3939instance eqPerm :: Eq Perm where
40- eq (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
40+ eq (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4141 r1 == r2 && w1 == w2 && x1 == x2
4242
4343instance ordPerm :: Ord Perm where
44- compare (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
44+ compare (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4545 compare [r1, w1, x1] [r2, w2, x2]
4646
4747instance showPerm :: Show Perm where
4848 show p | p == none = " none"
4949 show p | p == all = " all"
50- show (Perm { r = r, w = w, x = x }) =
50+ show (Perm { r: r, w: w, x: x }) =
5151 joinWith " + " ps
5252 where
5353 ps =
@@ -56,10 +56,10 @@ instance showPerm :: Show Perm where
5656 (if x then [" execute" ] else [] )
5757
5858instance semiringPerm :: Semiring Perm where
59- add (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
59+ add (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6060 Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
6161 zero = Perm { r: false , w: false , x: false }
62- mul (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
62+ mul (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6363 Perm { r: r0 && r1, w: w0 && w1, x: x0 && x1 }
6464 one = Perm { r: true , w: true , x: true }
6565
@@ -97,15 +97,15 @@ all = one
9797newtype Perms = Perms { u :: Perm , g :: Perm , o :: Perm }
9898
9999instance eqPerms :: Eq Perms where
100- eq (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
100+ eq (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
101101 u1 == u2 && g1 == g2 && o1 == o2
102102
103103instance ordPerms :: Ord Perms where
104- compare (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
104+ compare (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
105105 compare [u1, g1, o1] [u2, g2, o2]
106106
107107instance showPerms :: Show Perms where
108- show (Perms { u = u, g = g, o = o }) =
108+ show (Perms { u: u, g: g, o: o }) =
109109 " mkPerms " <> joinWith " " (f <$> [u, g, o])
110110 where
111111 f perm = let str = show perm
@@ -154,7 +154,7 @@ mkPerms u g o = Perms { u: u, g: g, o: o }
154154-- | * `permToInt w == 2`
155155-- | * `permToInt (r + w) == 6`
156156permToInt :: Perm -> Int
157- permToInt (Perm { r = r, w = w, x = x }) =
157+ permToInt (Perm { r: r, w: w, x: x }) =
158158 (if r then 4 else 0 )
159159 + (if w then 2 else 0 )
160160 + (if x then 1 else 0 )
@@ -167,12 +167,12 @@ permToString = show <<< permToInt
167167-- | accepted by `chmod`. For example:
168168-- | `permsToString (mkPerms (read + write) read read) == "0644"`
169169permsToString :: Perms -> String
170- permsToString (Perms { u = u, g = g, o = o }) =
170+ permsToString (Perms { u: u, g: g, o: o }) =
171171 " 0"
172- ++ permToString u
173- ++ permToString g
174- ++ permToString o
172+ <> permToString u
173+ <> permToString g
174+ <> permToString o
175175
176176-- | Convert a `Perms` value to an `Int`, via `permsToString`.
177177permsToInt :: Perms -> Int
178- permsToInt = fromJust <<< fromNumber <<< readInt 8 <<< permsToString
178+ permsToInt = unsafePartial $ fromJust <<< fromNumber <<< readInt 8 <<< permsToString
0 commit comments