From 436c36cc1e37bcc0764678afc9114370694a0ff3 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Wed, 31 May 2006 20:55:21 +0000 Subject: [PATCH] added pathlist-closure to file.ss svn: r3160 --- collects/mzlib/file.ss | 26 ++++++++++++++++++++++++-- collects/mzlib/zip.ss | 18 ++---------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/collects/mzlib/file.ss b/collects/mzlib/file.ss index 88f13e4a90..69cadafecc 100644 --- a/collects/mzlib/file.ss +++ b/collects/mzlib/file.ss @@ -20,7 +20,8 @@ call-with-output-file* fold-files - find-files) + find-files + pathlist-closure) (require "list.ss" "etc.ss") @@ -496,4 +497,25 @@ (reverse! (fold-files (lambda (path kind acc) (if (f path) (cons path acc) acc)) null - path))))) + path)))) + + (define (pathlist-closure paths) + (let loop ([paths (map (lambda (p) (simplify-path p #f)) paths)] + [r '()]) + (if (null? paths) + (reverse! r) + (let loop2 ([path (car paths)] + [new (cond [(file-exists? (car paths)) + (list (car paths))] + [(directory-exists? (car paths)) + (find-files void (car paths))] + [else (error 'pathlist-closure + "file/directory not found: ~a" + (car paths))])]) + (let-values ([(base name dir?) (split-path path)]) + (if (path? base) + (loop2 base (if (or (member base r) (member base paths)) + new (cons base new))) + (loop (cdr paths) (append! (reverse! new) r)))))))) + + ) diff --git a/collects/mzlib/zip.ss b/collects/mzlib/zip.ss index f15e813248..c18d494153 100644 --- a/collects/mzlib/zip.ss +++ b/collects/mzlib/zip.ss @@ -262,21 +262,7 @@ (provide zip) (define (zip zip-file . paths) (when (null? paths) (error 'zip "no paths specified")) - (let loop ([paths (map (lambda (p) (simplify-path p #f)) paths)] - [r '()]) - (if (null? paths) - (with-output-to-file zip-file (lambda () (zip->output (reverse! r)))) - (let loop2 ([path (car paths)] - [new (cond [(file-exists? (car paths)) - (list (car paths))] - [(directory-exists? (car paths)) - (find-files void (car paths))] - [else (error 'zip "file/directory not found: ~a" - (car paths))])]) - (let-values ([(base name dir?) (split-path path)]) - (if (path? base) - (loop2 base (if (or (member base r) (member base paths)) - new (cons base new))) - (loop (cdr paths) (append! (reverse! new) r)))))))) + (with-output-to-file zip-file + (lambda () (zip->output (pathlist-closure paths))))) )