Created
May 21, 2012 16:07
-
-
Save alaa-alawi/2763054 to your computer and use it in GitHub Desktop.
implementation comparision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; original implementation | |
;; hunchentoot;utils.lisp | |
;; | |
(let ((counter 0)) | |
(declare (ignorable counter)) | |
(defun make-tmp-file-name (&optional (prefix "hunchentoot")) | |
"Generates a unique name for a temporary file. This function is | |
called from the RFC2388 library when a file is uploaded." | |
(let ((tmp-file-name | |
#+:allegro | |
(pathname (system:make-temp-file-name prefix *tmp-directory*)) | |
#-:allegro | |
(loop for pathname = (make-pathname :name (format nil "~A-~A" | |
prefix (incf counter)) | |
:type nil | |
:defaults *tmp-directory*) | |
unless (probe-file pathname) | |
return pathname))) | |
(push tmp-file-name *tmp-files*) | |
;; maybe call hook for file uploads | |
(when *file-upload-hook* | |
(funcall *file-upload-hook* tmp-file-name)) | |
tmp-file-name))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; users are responsible for making sure *file-upload-hook* is called in their supplied implementation in *upload-filename-generator* | |
;; | |
;; make-tmp-file-name implementation is the same as the original one | |
(defun make-upload-filename () | |
(let ((designator (cond | |
;; the old behaviour. | |
((null *upload-filename-generator*) | |
t) | |
;; the new behaviour. | |
((or (symbolp *upload-filename-generator*) | |
(functionp *upload-filename-generator*)) | |
*upload-filename-generator*)))) | |
designator)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; we wrap the supplied one with our own lambda to ensure that *file-upload-hook* is called properly. | |
;;; make-tmp-file-name implementation is the same as the original one | |
(defun make-upload-filename () | |
(let ((designator (cond | |
;; the old behaviour. | |
((null *upload-filename-generator*) | |
t) | |
;; the new behaviour. | |
((or (symbolp *upload-filename-generator*) | |
(functionp *upload-filename-generator*)) | |
(lambda (&key field-name file-name content-type :allow-other-keys t) | |
(let ((filename (funcall *upload-filename-generator* | |
:field-name field-name | |
:file-name file-name | |
:content-type content-type | |
:allow-other-keys t))) | |
(when *file-upload-hook* | |
(funcall *file-upload-hook* filename)) | |
filename)))))) | |
designator)) |
(defun make-upload-filename ()
(etypecase *upload-filename-generator*
;; the old behaviour.
(null t)
;; the new behaviour.
((or symbol function)
(lambda (&rest args)
(let ((filename (apply *upload-filename-generator* args)))
(when *file-upload-hook*
(funcall *file-upload-hook* filename))
filename)))))
this should do it. and thanks for being patients with my questions.
https://gist.github.com/2763054#gistcomment-326330
…On Mon, May 21, 2012 at 8:48 PM, Hans Hübner ***@***.*** wrote:
Remove the &key arguments. The fact that _upload-filename-generator_ accepts keyword arguments is completely irrelevant for this wrapper lambda. It wraps the invocation to invoke the hook function, and that is all that the code should express.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2763054
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remove the &key arguments. The fact that upload-filename-generator accepts keyword arguments is completely irrelevant for this wrapper lambda. It wraps the invocation to invoke the hook function, and that is all that the code should express.