Skip to content

Commit 0b3fe98

Browse files
committed
More documentation updates for Perms
1 parent 38eb664 commit 0b3fe98

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,17 @@ newtype Perms
200200
```
201201

202202
A `Perms` value includes all the permissions information about a
203-
particular file or directory,
203+
particular file or directory, by storing a `Perm` value for each of the
204+
file owner, the group, and others.
204205

205206
#### `none`
206207

207208
``` purescript
208209
none :: Perm
209210
```
210211

211-
No permissions. This is the identity of the Semigroup (<>) operation for
212-
Perm.
212+
No permissions. This is the identity of the `Semigroup` operation `(<>)`
213+
for `Perm`.
213214

214215
#### `r`
215216

@@ -256,6 +257,9 @@ instance semigroupPerm :: Semigroup Perm
256257
permsFromString :: String -> Maybe Perms
257258
```
258259

260+
Attempt to parse a `Perms` value from a `String` containing an octal
261+
integer. For example,
262+
`permsFromString "644" == Just (mkPerms (r <> w) r r)`.
259263

260264
#### `mkPerms`
261265

@@ -272,13 +276,18 @@ others' permission sets, respectively.
272276
permsToString :: Perms -> String
273277
```
274278

279+
Convert a `Perms` value to an octal string, in a format similar to that
280+
accepted by `chmod`. For example:
281+
282+
* `permsToString (mkPerms (r <> w) r r) == "0644"`
275283

276284
#### `permsToInt`
277285

278286
``` purescript
279287
permsToInt :: Perms -> Int
280288
```
281289

290+
Convert a `Perms` value to an `Int`, via `permsToString`.
282291

283292
#### `showPerm`
284293

src/Node/FS/Perms.purs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import Data.Int (Int(), fromNumber, toNumber)
2626
newtype Perm = Perm { r :: Boolean, w :: Boolean, x :: Boolean }
2727

2828
-- | A `Perms` value includes all the permissions information about a
29-
-- | particular file or directory,
29+
-- | particular file or directory, by storing a `Perm` value for each of the
30+
-- | file owner, the group, and others.
3031
newtype Perms = Perms { u :: Perm, g :: Perm, o :: Perm }
3132

32-
-- | No permissions. This is the identity of the Semigroup (<>) operation for
33-
-- | Perm.
33+
-- | No permissions. This is the identity of the `Semigroup` operation `(<>)`
34+
-- | for `Perm`.
3435
none :: Perm
3536
none = Perm { r: false, w: false, x: false }
3637

@@ -54,10 +55,13 @@ instance semigroupPerm :: Semigroup Perm where
5455
(<>) (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
5556
Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
5657

58+
-- | Attempt to parse a `Perms` value from a `String` containing an octal
59+
-- | integer. For example,
60+
-- | `permsFromString "644" == Just (mkPerms (r <> w) r r)`.
5761
permsFromString :: String -> Maybe Perms
5862
permsFromString = _perms <<< toCharArray
5963
where
60-
_perms (u : g : o : []) =
64+
_perms [u, g, o] =
6165
mkPerms <$> permFromChar u
6266
<*> permFromChar g
6367
<*> permFromChar o
@@ -77,7 +81,7 @@ permFromChar = _perm <<< charString
7781
_perm _ = Nothing
7882

7983
-- | Create a `Perm` value. The arguments represent the readable, writable, and
80-
-- | executable permissions respectively.
84+
-- | executable permissions, in that order.
8185
mkPerm :: Boolean -> Boolean -> Boolean -> Perm
8286
mkPerm r w x = Perm { r: r, w: w, x: x }
8387

@@ -86,15 +90,25 @@ mkPerm r w x = Perm { r: r, w: w, x: x }
8690
mkPerms :: Perm -> Perm -> Perm -> Perms
8791
mkPerms u g o = Perms { u: u, g: g, o: o }
8892

93+
-- | Convert a `Perm` to an octal digit. For example:
94+
-- |
95+
-- | * `permToInt r == 4`
96+
-- | * `permToInt w == 2`
97+
-- | * `permToInt (r <> w) == 6`
8998
permToInt :: Perm -> Int
9099
permToInt (Perm { r = r, w = w, x = x }) = fromNumber $
91100
(if r then 4 else 0)
92101
+ (if w then 2 else 0)
93102
+ (if x then 1 else 0)
94103

104+
-- | Convert a `Perm` to an octal string, via `permToInt`.
95105
permToString :: Perm -> String
96106
permToString = show <<< toNumber <<< permToInt
97107

108+
-- | Convert a `Perms` value to an octal string, in a format similar to that
109+
-- | accepted by `chmod`. For example:
110+
-- |
111+
-- | * `permsToString (mkPerms (r <> w) r r) == "0644"`
98112
permsToString :: Perms -> String
99113
permsToString (Perms { u = u, g = g, o = o }) =
100114
"0"

0 commit comments

Comments
 (0)