- Timestamp:
- Jul 26, 2010, 6:08:10 PM (14 years ago)
- Location:
- branches/qres/ccl
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
level-1/l1-pathnames.lisp (modified) (1 diff)
-
lib/pathnames.lisp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/qres/ccl
- Property svn:mergeinfo changed
/trunk/source merged: 13579,13582
- Property svn:mergeinfo changed
-
branches/qres/ccl/level-1/l1-pathnames.lisp
r14049 r14051 388 388 ;; case-insensitive version for hosts. 389 389 ;; In addition, host components do not support wildcards. 390 (or (eq path-host wild-host) 390 (or (null wild-host) (eq wild-host :wild) 391 (null path-host) (eq path-host :wild) 392 (eq path-host wild-host) 391 393 (and (stringp path-host) 392 394 (stringp wild-host) -
branches/qres/ccl/lib/pathnames.lisp
r13070 r14051 314 314 (close-dir ,dirent))))) 315 315 316 (defun path-is-link (path) 317 "Returns T if PATH is a (hard or symbolic) link, NIL otherwise." 318 (eq (%unix-file-kind (native-translated-namestring path) t) :link)) 319 320 321 (defun %add-directory-result (path result follow-links) 322 (let* ((resolved (and follow-links (path-is-link path) (probe-file path)))) 323 (if resolved 324 (push (namestring resolved) (cdr result)) ; may introduce duplicates. 325 (push (namestring path) (car result))) 326 path)) 327 328 (defun %make-directory-result () 329 (cons nil nil)) 330 331 (defun %process-directory-result (result) 332 (dolist (resolved (cdr result) (mapcar #'parse-namestring (sort (car result) #'string<))) 333 (pushnew resolved (car result) :test #'string=))) 334 335 316 336 (defun directory (path &key (directories nil) ;; include subdirectories 317 337 (files t) ;; include files … … 342 362 (assert (eq (car (pathname-directory path)) :absolute) () 343 363 "full-pathname returned relative path ~s??" path) 344 ;; return sorted in alphabetical order, target-Xload-level-0 depends 345 ;; on this. 346 (nreverse 347 (delete-duplicates (%directory "/" dir path '(:absolute) keys) :test #'equal)))) 348 349 (defun %directory (dir rest path so-far keys) 364 (%process-directory-result (%directory "/" dir path '(:absolute) keys (%make-directory-result))))) 365 366 (defun %directory (dir rest path so-far keys result) 350 367 (multiple-value-bind (sub-dir wild rest) (%split-dir rest) 351 (%some-specific dir sub-dir wild rest path so-far keys )))352 353 (defun %some-specific (dir sub-dir wild rest path so-far keys )368 (%some-specific dir sub-dir wild rest path so-far keys result))) 369 370 (defun %some-specific (dir sub-dir wild rest path so-far keys result) 354 371 (let* ((start 1) 355 372 (end (length sub-dir)) … … 360 377 (setq start (%i+ 1 pos)))) 361 378 (cond ((null wild) 362 (%files-in-directory full-dir path so-far keys ))379 (%files-in-directory full-dir path so-far keys result)) 363 380 ((string= wild "**") 364 (%all-directories full-dir rest path so-far keys ))365 (t (%one-wild full-dir wild rest path so-far keys )))))381 (%all-directories full-dir rest path so-far keys result)) 382 (t (%one-wild full-dir wild rest path so-far keys result))))) 366 383 367 384 ; for a * or *x*y 368 (defun %one-wild (dir wild rest path so-far keys) 369 (let ((result ()) 370 (device (pathname-device path)) 385 (defun %one-wild (dir wild rest path so-far keys result) 386 (let ((device (pathname-device path)) 371 387 (all (getf keys :all)) 372 388 name) … … 381 397 (so-far (cons (%path-std-quotes name nil "/;:*") so-far))) 382 398 (declare (dynamic-extent so-far)) 383 (setq result 384 (nconc (%directory (%str-cat subdir "/") rest path so-far keys) result))))))399 (%directory (%str-cat subdir "/") rest path so-far keys result) 400 )))) 385 401 result)) 386 402 387 (defun %files-in-directory (dir path so-far keys )403 (defun %files-in-directory (dir path so-far keys result) 388 404 (let ((device (pathname-device path)) 389 405 (name (pathname-name path)) … … 396 412 (all (getf keys :all)) 397 413 (include-emacs-lockfiles (getf keys :include-emacs-lockfiles)) 398 (result ())399 414 sub dir-list ans) 400 415 (if (not (or name type)) … … 407 422 (%cons-pathname (reverse (cdr so-far)) (car so-far) nil nil device))) 408 423 (when (and ans (or (null test) (funcall test ans))) 409 (setq result (list ans)))))424 (%add-directory-result ans result follow-links)))) 410 425 (with-open-dir (dirent (pathname-device path) dir) 411 426 (while (setq sub (%read-dir dirent)) … … 428 443 (%cons-pathname (or dir-list (setq dir-list (reverse so-far))) name type nil device))))) 429 444 (when (and ans (or (null test) (funcall test ans))) 430 ( push (if follow-links (or (probe-file ans) ans) ans) result))))))445 (%add-directory-result ans result follow-links)))))) 431 446 result)) 432 447 433 (defun %all-directories (dir rest path so-far keys )448 (defun %all-directories (dir rest path so-far keys result) 434 449 (let ((do-files nil) 435 450 (do-dirs nil) 436 (result nil)437 451 (device (pathname-device path)) 438 452 (name (pathname-name path)) … … 451 465 (multiple-value-setq (next-dir next-wild next-rest) (%split-dir rest))) 452 466 (cond ((not (string= next-dir "/")) 453 (setq result 454 (%some-specific dir next-dir next-wild next-rest path so-far keys))) 467 (%some-specific dir next-dir next-wild next-rest path so-far keys result)) 455 468 (next-wild 456 (setq result 457 (%one-wild dir next-wild next-rest path so-far keys))) 469 (%one-wild dir next-wild next-rest path so-far keys result)) 458 470 ((or name type) 459 471 (when (getf keys :files) (setq do-files t)) … … 464 476 (%cons-pathname (reverse (cdr so-far)) (car so-far) nil nil device))) 465 477 (when (or (null test) (funcall test sub)) 466 (setq result (list (if follow-links (truename sub) sub)))))))) 467 ; now descend doing %all-dirs on dirs and collecting files & dirs if do-x is t 468 (with-open-dir (dirent device dir) 478 (%add-directory-result sub result follow-links)))))) 479 ;; now descend doing %all-dirs on dirs and collecting files & dirs 480 ;; if do-x is t 481 (with-open-dir (dirent device (%path-std-quotes dir nil "*;:")) 469 482 (while (setq sub (%read-dir dirent)) 470 483 (when (and (or all (neq (%schar sub 0) #\.)) … … 475 488 (std-sub (%path-std-quotes sub nil "/;:*")) 476 489 (so-far (cons std-sub so-far)) 477 (subdir (%str-cat subfile "/")))490 (subdir (%str-cat subfile "/"))) 478 491 (declare (dynamic-extent so-far)) 479 492 (when (and do-dirs (%file*= name type sub)) … … 483 496 std-sub nil nil device))) 484 497 (when (or (null test) (funcall test ans)) 485 ( push (if follow-links (truename ans) ans) result)))486 ( setq result (nconc (%all-directories subdir rest path so-far keys) result)))498 (%add-directory-result ans result follow-links))) 499 (%all-directories subdir rest path so-far keys result)) 487 500 (when (and do-files (%file*= name type sub)) 488 501 (multiple-value-bind (name type) (%std-name-and-type sub) 489 502 (setq ans (%cons-pathname (or dir-list (setq dir-list (reverse so-far))) name type nil device)) 490 503 (when (or (null test) (funcall test ans)) 491 ( push (if follow-links (truename ans) ans) result))))))))504 (%add-directory-result ans result follow-links)))))))) 492 505 result)) 493 506
Note:
See TracChangeset
for help on using the changeset viewer.
