Changeset 15989 in project


Ignore:
Timestamp:
09/20/09 17:29:33 (10 years ago)
Author:
sjamaan
Message:

Make delete work too, so files will not stick around all the time

Location:
release/4/qwiki/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/qwiki/trunk/qwiki-post-commit-hook.scm

    r15498 r15989  
    3434;;  POSSIBILITY OF SUCH DAMAGE.
    3535
    36 (use posix svn-client qwiki-svn)
     36(use posix svn-client qwiki-svn qwiki-sxml qwiki qwiki-search)
    3737
    3838(qwiki-repos-uri (conc "file://" (car (command-line-arguments))))
    3939;(define rev (cadr (command-line-arguments)))
    4040
    41 ;; These can be overridden in a shellscript that calls this script,
    42 ;; but if the defaults are ok, this executable can also be placed under
    43 ;; hooks/post-commit directly.
    44 (define qwiki-source-path
    45   (make-parameter (or (get-environment-variable "QWIKI_SOURCE_PATH")
    46                       "/tmp/qwiki")))
     41;; TODO: This ought to be configurable!
     42(search-install!)
    4743
    48 (define qwiki-web-path
    49   (make-parameter (or (get-environment-variable "QWIKI_WEB_PATH")
    50                       "/var/www")))
    51 
    52 (define (remove-tree path)
    53   (if (and (directory? path) (not (symbolic-link? path)))
    54       (begin
    55         (for-each remove-tree (directory path #t))
    56         (delete-directory path))
    57       (delete-file* path)))
    58 
     44;; TODO: How do we clean up directories?
    5945(and-let* (((directory? (qwiki-source-path)))
    6046           (info-list '())
     
    6955           ((pair? info-list))
    7056           (revision (svn-info-rev (car info-list))))
     57  ;; First, get the files up to date. We use this as a guide to see what
     58  ;; to do with the generated information. If the file is missing, we can
     59  ;; delete it. If was added or modified it will exist, and we can update it.
     60  (update-sources! (qwiki-source-path))
    7161  (svn-client-log
    7262   (qwiki-repos-uri) (make-svn-opt-revision-number revision)
     
    7767      (lambda (path/changed-path-pair)
    7868        (let ((path (car path/changed-path-pair)))
    79           ;; For all the files that changed, remove their matching HTML file.
    80           ;; If they are a directory, remove that dir (because it might have
    81           ;; been renamed or removed completely)
    82           ;; All files can be regenerated when needed.
    83           (if (directory? (make-pathname (qwiki-source-path) path))
    84               (remove-tree (make-pathname (qwiki-web-path) path))
    85               (remove-tree (make-pathname (qwiki-web-path) path "html")))))
    86       paths)))
    87   ;; Finally, get us up to date
    88   (update-sources! (qwiki-source-path)))
     69          (if (file-exists? (make-pathname (qwiki-source-path) path))
     70              (qwiki-update-file! (string-split path "/"))
     71              (qwiki-delete-file! (string-split path "/")))))
     72      paths))))
  • release/4/qwiki/trunk/qwiki-search.scm

    r15969 r15989  
    9191
    9292(define (delete-search-entry! path)
    93   (delete-document (search-server-uri) "qwiki" uri: (string-join path "/")))
     93  (condition-case
     94      (delete-document (search-server-uri) "qwiki" uri: (string-join path "/"))
     95    ((exn estraier-client args) (void)))) ;; Ignore already deleted entries
    9496
    9597(define search-rules
  • release/4/qwiki/trunk/qwiki.scm

    r15969 r15989  
    3434;;  POSSIBILITY OF SUCH DAMAGE.
    3535
     36;; TODO: Attempt to split out all Spiffy and URI-related stuff.
     37;; This makes things like the post-commit-hook much more lightweight.
     38
    3639(module qwiki
    37   (qwiki-docroot
     40  (qwiki-docroot
     41   qwiki-web-path
    3842   qwiki-source-path
    3943   qwiki-base-uri
     
    6367(define qwiki-docroot (make-parameter "/"))
    6468
     69;; The docroot. This will be parameterize to be identical to the Spiffy
     70;; docroot when running inside the webserver.  The post-commit-hook
     71;; could need to customize this.
     72(define qwiki-web-path
     73  (make-parameter
     74   (or (get-environment-variable "QWIKI_WEB_PATH") "/var/www")))
     75
    6576;; The location of the wiki source files (where a checkout will be made)
    66 (define qwiki-source-path (make-parameter "/tmp/qwiki"))
     77(define qwiki-source-path
     78  (make-parameter
     79   (or (get-environment-variable "QWIKI_SOURCE_PATH") "/tmp/qwiki")))
    6780
    6881;; The base URI for this wiki
     
    171184
    172185(define (qwiki-edit path req)
    173   (let* ((html-file (path->html-filename path))
    174          (source-file (path->source-filename path))
     186  (let* ((source-file (path->source-filename path))
    175187         (postdata (if (eq? 'POST (request-method req))
    176188                       (form-urldecode (read-request-data req))
     
    268280  ;; TODO: What if someone did something else than GET or HEAD?
    269281  (let* ((html-file (path->html-filename path))
     282         (html-path (make-pathname (qwiki-web-path) html-file))
    270283         (source-file (path->source-filename path))
    271284         (rev (string->number
     
    278291               source-file rev wiki-parse)))
    279292            (begin
    280               (when (or (not (file-exists? html-file))
    281                         (file-newer? source-file html-file))
     293              (when (or (not (file-exists? html-path))
     294                        (file-newer? source-file html-path))
    282295                (qwiki-update-file! path))
    283296             (send-static-file html-file)))
     
    289302;; Generate new cached HTML file
    290303(define (regenerate-html-file! path page)
    291   (let ((html-file (make-pathname (root-path) (path->html-filename path))))
     304  (let ((html-file (make-pathname (qwiki-web-path) (path->html-filename path))))
    292305    (with-output-to-path html-file
    293306      (lambda ()
     
    302315
    303316(define (delete-html-file! path)
    304   (delete-file* (make-pathname (root-path) (path->html-filename path))))
     317  (let ((basename
     318         (make-pathname (qwiki-docroot)
     319                        (string-join (cons (qwiki-web-path) path) "/"))))
     320    (if (and (directory? basename) (not (symbolic-link? basename)))
     321        (begin
     322          (for-each delete-html-file! (directory basename #t))
     323          (delete-directory basename))
     324        (delete-file* (string-append basename ".html")))))
    305325
    306326(define (qwiki-delete-file! path)
     
    337357;; Spiffy handler for requests that should be routed to the wiki
    338358(define (qwiki-handler continue)
    339   (ensure-latest-sources!)
    340   (let ((uri (request-uri (current-request))))
    341     (cond
    342      ((find (lambda (a)
    343               (equal? (uri-path uri) (list '/ (->string (car a)))))
    344             (qwiki-global-action-handlers))
    345       => (lambda (handler)
    346            ((cdr handler) (current-request))))
    347      ((any impossible-filename? (cdr (uri-path uri))) ; assumed to be absolute
    348       (read-request-data (current-request))
    349       (send-status 404 "Not found"))
    350      (else (let* ((action (string->symbol
    351                            (alist-ref 'action (uri-query uri) eq? "show")))
    352                   (handler (alist-ref action
    353                                       (qwiki-page-action-handlers)
    354                                       eq? qwiki-show)))
    355              (handler (normalize-path (relative-uri-path uri))
    356                       (current-request)))))))
     359  (parameterize ((qwiki-web-path (root-path)))
     360   (ensure-latest-sources!)
     361   (let ((uri (request-uri (current-request))))
     362     (cond
     363      ((find (lambda (a)
     364               (equal? (uri-path uri) (list '/ (->string (car a)))))
     365             (qwiki-global-action-handlers))
     366       => (lambda (handler)
     367            ((cdr handler) (current-request))))
     368      ((any impossible-filename? (cdr (uri-path uri))) ; assumed to be absolute
     369       (read-request-data (current-request))
     370       (send-status 404 "Not found"))
     371      (else (let* ((action (string->symbol
     372                            (alist-ref 'action (uri-query uri) eq? "show")))
     373                   (handler (alist-ref action
     374                                       (qwiki-page-action-handlers)
     375                                       eq? qwiki-show)))
     376              (handler (normalize-path (relative-uri-path uri))
     377                       (current-request))))))))
    357378
    358379)
Note: See TracChangeset for help on using the changeset viewer.