* ftw visited ino+devno
@ 2006-10-04 22:11 Kevin Ryde
2006-10-04 22:32 ` Neil Jerram
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Ryde @ 2006-10-04 22:11 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 146 bytes --]
I made the change below in ice-9/ftw.scm to check the dev number of
files visited, the inode number is of course only unique within each
device.
[-- Attachment #2: ftw.scm.ino.diff --]
[-- Type: text/plain, Size: 1627 bytes --]
--- ftw.scm.~1.4.2.1.~ 2006-02-14 08:58:55.000000000 +1100
+++ ftw.scm 2006-10-05 08:09:16.000000000 +1000
@@ -217,14 +217,33 @@
(define (abs? filename)
(char=? #\/ (string-ref filename 0)))
+;; `visited?-proc' returns a test procedure VISITED? which when called as
+;; (VISITED? stat-obj) returns #f the first time a distinct file is seen,
+;; then #t on any subsequent sighting of it.
+;;
+;; stat:dev and stat:ino together uniquely identify a file (see "Attribute
+;; Meanings" in the glibc manual). Often there'll be just one dev, and
+;; usually there's just a handful mounted, so the strategy here is a small
+;; hash table indexed by dev, containing hash tables indexed by ino.
+;;
+;; It'd be possible to make a pair (dev . ino) and use that as the key to a
+;; single hash table. It'd use an extra pair for every file visited, but
+;; might be a little faster if it meant less scheme code.
+;;
(define (visited?-proc size)
- (let ((visited (make-hash-table size)))
+ (let ((dev-hash (make-hash-table 7)))
(lambda (s)
- (and s (let ((ino (stat:ino s)))
- (or (hash-ref visited ino)
- (begin
- (hash-set! visited ino #t)
- #f)))))))
+ (and s
+ (let ((ino-hash (hashv-ref dev-hash (stat:dev s)))
+ (ino (stat:ino s)))
+ (or ino-hash
+ (begin
+ (set! ino-hash (make-hash-table size))
+ (hashv-set! dev-hash (stat:dev s) ino-hash)))
+ (or (hashv-ref ino-hash ino)
+ (begin
+ (hashv-set! ino-hash ino #t)
+ #f)))))))
(define (stat-dir-readable?-proc uid gid)
(let ((uid (getuid))
[-- Attachment #3: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ftw visited ino+devno
2006-10-04 22:11 ftw visited ino+devno Kevin Ryde
@ 2006-10-04 22:32 ` Neil Jerram
2006-10-04 22:45 ` Kevin Ryde
0 siblings, 1 reply; 3+ messages in thread
From: Neil Jerram @ 2006-10-04 22:32 UTC (permalink / raw)
Kevin Ryde <user42@zip.com.au> writes:
> I made the change below in ice-9/ftw.scm to check the dev number of
> files visited, the inode number is of course only unique within each
> device.
Looks nice. I infer that the previous version was bugged because of
the possibility of having the same inode on different devices; is that
right?
Is it worth commenting that the use of dev+ino (as opposed to
pathname) avoids traversing hard links (notably . and ..) multiple
times, or is that too obvious?
Regards,
Neil
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-10-04 22:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-04 22:11 ftw visited ino+devno Kevin Ryde
2006-10-04 22:32 ` Neil Jerram
2006-10-04 22:45 ` Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).