summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-04-22 06:21:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-04-22 06:21:33 -0700
commitb2735927060a866ff863370a20f00f3a5e73ef38 (patch)
tree7b7d8d6686945dd301b812620083c4f0a71dcd08 /share
parentd9f9ae14ba19c519b08ac41467d9c8ab94b2280f (diff)
downloadtxr-b2735927060a866ff863370a20f00f3a5e73ef38.tar.gz
txr-b2735927060a866ff863370a20f00f3a5e73ef38.tar.bz2
txr-b2735927060a866ff863370a20f00f3a5e73ef38.zip
Optimization in path-private-to-me-p.
* share/txr/stdlib/path-test.tl (path-private-to-me-p): Use mlet to initialize the g variable lazily, so that getgrgid is only called when g is used. getgrid is a fairly heavy-weight function, and it's only used to resolve the case when a file is writable to the group owner (is the user the only member of that group?)
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/path-test.tl16
1 files changed, 8 insertions, 8 deletions
diff --git a/share/txr/stdlib/path-test.tl b/share/txr/stdlib/path-test.tl
index bc71cc4c..851ac61b 100644
--- a/share/txr/stdlib/path-test.tl
+++ b/share/txr/stdlib/path-test.tl
@@ -100,14 +100,14 @@
(defun path-private-to-me-p (path)
(sys:path-test (s stat path)
(let ((m s.mode)
- (euid (geteuid))
- (g (getgrgid s.gid)))
- (and (eql euid s.uid)
- (zerop (logand m s-iwoth))
- (or (zerop (logand m s-iwgrp))
- (null g.mem)
- (and (not (rest g.mem))
- (equal (getpwuid euid).name (first g.mem))))))))
+ (euid (geteuid)))
+ (mlet ((g (getgrgid s.gid)))
+ (and (eql euid s.uid)
+ (zerop (logand m s-iwoth))
+ (or (zerop (logand m s-iwgrp))
+ (null g.mem)
+ (and (not (rest g.mem))
+ (equal (getpwuid euid).name (first g.mem)))))))))
(defmacro sys:path-examine ((var statfun path) . body)
^[sys:do-path-test ,statfun ,path