diff --git a/collects/meta/tree/plt-tree.ss b/collects/meta/tree/plt-tree.ss index 54c8391cd8..deda3a2e8b 100644 --- a/collects/meta/tree/plt-tree.ss +++ b/collects/meta/tree/plt-tree.ss @@ -1,7 +1,35 @@ #lang scheme/base +(provide get-tree get-plt-tree) + (require "tree.ss" setup/dirs) +;; ---------------------------------------------------------------------------- +;; Reading a tree from a directory + +(define (get-tree path) + (define path* (simplify-path path)) + (let loop ([path path*] + [name (regexp-replace #rx#"/$" (path->bytes path*) #"")]) + (cond [(directory-exists? path) + (make-tree + (bytes-append name #"/") + (parameterize ([current-directory path]) + (let* ([subs (map (lambda (sub) + (cons (path-element->bytes sub) sub)) + (directory-list))] + [subs (sort subs bytesrl x) (let ([r (e `(glob->regexp-or-literal ,x))]) (if (byte-regexp? r) `(rx ,(object-name r)) r))) @@ -42,9 +42,13 @@ (g->rl #"gl[]*]ob") => '(rx #"^gl[]*]ob$") (g->rl #"gl[^]*]ob") => '(rx #"^gl[^]*]ob$") (g->rl #"gl[^]*]*ob") => '(rx #"^gl[^]*].*ob$") - )) + ) + (kill-evaluator e)) (define (tree-tests) + (define e + (call-with-trusted-sandbox-configuration + (lambda () (make-module-evaluator plt-tree-module)))) (define a-dir (collection-path "scribble")) (define a-list (find-files void a-dir)) (define a-tree #f) @@ -3904,7 +3908,8 @@ => same-as-last-datums ;; no .svn or compiled directories using `and:' (e/filter '(and: (not: "**/.svn/") (not: "**/compiled/"))) - => same-as-last-datums)) + => same-as-last-datums) + (kill-evaluator e)) (test do (glob-tests) do (tree-tests)) diff --git a/collects/meta/tree/tree.ss b/collects/meta/tree/tree.ss index 4d21776f81..6d7e2d595a 100644 --- a/collects/meta/tree/tree.ss +++ b/collects/meta/tree/tree.ss @@ -1,7 +1,7 @@ #lang scheme/base (provide (struct-out tree) leaf? tree-foldl tree-foldr tree-for-each tree->list - and: or: not: tree-filter get-tree) + and: or: not: tree-filter) (require scheme/list) @@ -235,26 +235,3 @@ (error 'tree-filter "expecting a non-leaf, got ~e" tree) (or (subs-filter pred tree) (make-tree (tree-name tree) '() (tree-path tree))))) - -;; ---------------------------------------------------------------------------- -;; Reading a tree from a directory - -(define (get-tree path) - (define path* (simplify-path path)) - (let loop ([path path*] - [name (regexp-replace #rx#"/$" (path->bytes path*) #"")]) - (cond [(directory-exists? path) - (make-tree - (bytes-append name #"/") - (parameterize ([current-directory path]) - (let* ([subs (map (lambda (sub) - (cons (path-element->bytes sub) sub)) - (directory-list))] - [subs (sort subs bytes